#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <typename X>
inline bool minimize(X& p, X q) {
  if (p <= q) return 0;
  p = q;
  return 1;
}
template <typename X>
inline bool maximize(X& p, X q) {
  if (p >= q) return 0;
  p = q;
  return 1;
}
int T;
char S[205];
int cnt1[10], cnt2[10];
int main() {
  cin >> T >> S;
  for (int i = T; i; i /= 10) ++cnt1[i % 10];
  cnt1[2] += cnt1[5];
  cnt1[6] += cnt1[9];
  cnt1[5] = cnt1[9] = 0;
  for (int i = 0; S[i]; ++i) ++cnt2[S[i] - '0'];
  cnt2[2] += cnt2[5];
  cnt2[6] += cnt2[9];
  cnt2[5] = cnt2[9] = 0;
  int ans = INF;
  for (int i = 0; i < 10; ++i)
    if (cnt1[i]) minimize(ans, cnt2[i] / cnt1[i]);
  cout << ans << endl;
  return 0;
}
