#include <bits/stdc++.h>
using namespace std;
int a[15], b[15], c[15];
char y[1080], x[1080];
int main() {
  int i, ch = 0;
  cin >> x;
  cin >> y;
  for (int i = 0; i < strlen(x); i++) {
    a[x[i] - '0']++;
  }
  a[2] += a[5];
  a[5] = 0;
  a[6] += a[9];
  a[9] = 0;
  for (int i = 0; i < strlen(y); i++) {
    b[y[i] - '0']++;
  }
  b[2] += b[5];
  b[5] = 0;
  b[6] += b[9];
  b[9] = 0;
  int mi = 9999999;
  for (int i = 0; i < 10; i++) {
    if (a[i] != 0) {
      if (b[i] >= a[i] && b[i] != 0 && mi > (b[i] / a[i]))
        mi = b[i] / a[i], ch = 1;
    }
  }
  if (ch == 1)
    cout << mi << endl;
  else
    cout << 0 << endl;
  return 0;
}
