#include <bits/stdc++.h>
using namespace std;
char A[32], B[256];
int f1[10], f2[10];
int a25, a69;
int main() {
  int r = 1024;
  scanf("%s%s", A, B);
  for (int i = 0; A[i]; ++i)
    if (A[i] == '5')
      ++f1[2];
    else if (A[i] == '9')
      ++f1[6];
    else
      ++f1[A[i] - '0'];
  for (int i = 0; B[i]; ++i) {
    if (B[i] == '5')
      ++f2[2];
    else if (B[i] == '9')
      ++f2[6];
    else
      ++f2[B[i] - '0'];
  }
  for (int i = 0; i < 10; ++i)
    if (f1[i]) r = min(r, f2[i] / f1[i]);
  printf("%d", r);
  return 0;
}
