#include <bits/stdc++.h>
using namespace std;
const double epsilon = 1e-7;
void add(int &A, int B, int MOD) { A = (A + B) % MOD; }
int T;
vector<int> fr(10, 0), need(10, 0);
int main() {
  int lg, i, minn = INT_MAX, maxx;
  string S;
  cin >> T >> S;
  lg = S.length();
  for (auto x : S) {
    ++fr[x - '0'];
  }
  fr[2] = fr[5] = fr[2] + fr[5];
  fr[6] = fr[9] = fr[6] + fr[9];
  do {
    ++need[T % 10];
    T /= 10;
  } while (T);
  for (i = 0; i < 10; ++i) {
    if (need[i] && i != 5 && i != 2 && i != 6 && i != 9) {
      minn = min(minn, fr[i] / need[i]);
    }
  }
  if (need[2] || need[5]) {
    maxx = 0;
    for (i = 0; i <= fr[2]; ++i) {
      int val = INT_MAX;
      if (need[2]) {
        if (i) {
          val = i / need[2];
        } else
          val = 0;
      }
      if (need[5]) {
        if (fr[2] - i) {
          val = min(val, (fr[2] - i) / need[5]);
        } else
          val = 0;
      }
      if (val != INT_MAX) {
        maxx = max(maxx, val);
      }
    }
    minn = min(minn, maxx);
  }
  if (need[6] || need[9]) {
    maxx = 0;
    for (i = 0; i <= fr[6]; ++i) {
      int val = INT_MAX;
      if (need[6]) {
        if (i) {
          val = i / need[6];
        } else
          val = 0;
      }
      if (need[9]) {
        if (fr[6] - i) {
          val = min(val, (fr[6] - i) / need[9]);
        } else
          val = 0;
      }
      if (val != INT_MAX) {
        maxx = max(maxx, val);
      }
    }
    minn = min(minn, maxx);
  }
  printf("%d", minn);
  return 0;
}
