#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10] = {0}, t[10] = {0};
  char c;
  int re = 200, i = 0;
  while (cin.get(c), c != '\n') t[c - '0']++;
  while (cin.get(c), c != '\n') a[c - '0']++;
  t[2] += t[5];
  a[2] += a[5];
  t[5] = a[5] = 0;
  t[6] += t[9];
  a[6] += a[9];
  t[9] = a[9] = 0;
  for (i = 0; i < 9; ++i) {
    if (t[i]) {
      re = a[i] / t[i] < re ? a[i] / t[i] : re;
    }
  }
  cout << re << endl;
  return 0;
}
