#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[210], b[210];
  scanf("%s %s", a, b);
  int na = strlen(a), nb = strlen(b);
  int reva[11] = {0}, revb[11] = {0};
  for (int i = int(0); i < int(na); i++) {
    if (a[i] == '2')
      reva[5]++;
    else if (a[i] == '6')
      reva[9]++;
    else
      reva[a[i] - '0']++;
  }
  for (int i = int(0); i < int(nb); i++) {
    if (b[i] == '2')
      revb[5]++;
    else if (b[i] == '6')
      revb[9]++;
    else
      revb[b[i] - '0']++;
  }
  bool sw = false;
  int mini = 999999;
  for (int i = int(0); i < int(10); i++) {
    if (revb[i] == 0 && reva[i] > 0) {
      sw = true;
      break;
    } else {
      if (revb[i] > 0 && reva[i] > 0) mini = min(mini, revb[i] / reva[i]);
    }
  }
  if (sw)
    puts("0");
  else
    cout << mini << endl;
  return 0;
}
