#include <bits/stdc++.h>
using namespace std;
int dig[10];
int main() {
  memset(dig, 0, sizeof(dig));
  int t = 0;
  scanf("%d", &t);
  int tt = t;
  while (tt != 0) {
    if (tt % 10 == 9)
      dig[6]++;
    else if (tt % 10 == 5)
      dig[2]++;
    else
      dig[tt % 10]++;
    tt /= 10;
  }
  char s[300];
  scanf("%s", s);
  int rec[10] = {0};
  for (int i = 0; i < (signed)strlen(s); i++) {
    if (s[i] - '0' == 9)
      rec[6]++;
    else if (s[i] - '0' == 5)
      rec[2]++;
    else
      rec[s[i] - '0']++;
  }
  int minx = 1 << 30;
  for (int i = 0; i < 10; i++) {
    if (i == 5 || i == 9 || dig[i] == 0) continue;
    if (rec[i] / dig[i] < minx) minx = rec[i] / dig[i];
  }
  printf("%d\n", minx);
  return 0;
}
