#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10, MOD = 998244353;
int a[N], s[N], dp[N];
string g[210];
void solve() {
int m = 0;
for (string s; cin >> s, s != "."; g[++m] = s) ;
string s = " ";
for (string t; cin >> t; s += t) ;
int n = s.size() - 1;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int len = g[j].size(); //为什么不设一个len直接用会RE两点?
if (i - len >= 0 && dp[i - len] && g[j] == s.substr(i - len + 1, len))
dp[i] = 1;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) if (dp[i]) ans = i;
cout << ans << "\n";
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
}