#include <bits/stdc++.h>
using namespace std;
int main() {
  char t[7], s[202];
  int a[10], b[10];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> t >> s;
  int len1, len2;
  len1 = strlen(t);
  len2 = strlen(s);
  for (int i = 0; i < len2; i++) a[s[i] - '0']++;
  for (int i = 0; i < len1; i++) b[t[i] - '0']++;
  b[2] += b[5];
  b[5] = 0;
  b[6] += b[9];
  b[9] = 0;
  a[2] += a[5];
  a[5] = 0;
  a[6] += a[9];
  a[9] = 0;
  int minm = 1e6;
  for (int i = 0; i < 10; i++)
    if (b[i] != 0) {
      int c = a[i] / b[i];
      if (c < minm) minm = c;
    }
  cout << minm << endl;
  return 0;
}
