#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  string s;
  cin >> s;
  map<char, long long> m, m1;
  for (long long i = 0; i < (long long)s.size(); i++) {
    if (s[i] - '0' == 5)
      m[2]++;
    else if (s[i] - '0' == 9)
      m[6]++;
    else
      m[s[i] - '0']++;
  }
  long long a[10] = {};
  while (t > 0) {
    long long c = t % 10;
    if (c == 5)
      a[2]++;
    else if (c == 9)
      a[6]++;
    else
      a[c]++;
    t /= 10;
  }
  long long ans = INT_MAX;
  for (long long i = 0; i < 8; i++) {
    if (i == 5) continue;
    if (a[i] > 0) ans = min(ans, m[i] / a[i]);
  }
  if (ans == INT_MAX)
    cout << 0 << '\n';
  else
    cout << ans << '\n';
}
