#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, N = 1e6 + 1;
int main() {
  long long t;
  string s;
  cin >> t >> s;
  map<long long, long long> mp;
  for (long long i = 0; i < s.length(); i++) {
    long long p = s[i] - '0';
    if (p == 2 || p == 5) {
      mp[2]++;
      mp[5]++;
    } else if (p == 6 || p == 9) {
      mp[6]++;
      mp[9]++;
    } else
      mp[p]++;
  }
  long long m = t, ans = 0;
  while (1) {
    if (m == 0) {
      ans++;
      m = t;
    }
    long long g = m % 10;
    m = m / 10;
    if (mp[g] == 0)
      break;
    else if (g == 2 || g == 5) {
      mp[2]--;
      mp[5]--;
    } else if (g == 6 || g == 9) {
      mp[6]--;
      mp[9]--;
    } else
      mp[g]--;
  }
  cout << ans;
  return 0;
}
