#include <bits/stdc++.h>
using namespace std;
int cnt[20];
int main() {
  string a, b;
  cin >> a >> b;
  int sz = b.size();
  for (int i = 0; i < sz; i++) {
    if (b[i] == '2' || b[i] == '5')
      cnt[12]++;
    else if (b[i] == '6' || b[i] == '9')
      cnt[16]++;
    else
      cnt[b[i] - '0']++;
  }
  sz = a.size();
  int cn = 0;
  while (true) {
    for (int i = 0; i < sz; i++) {
      if (a[i] - '0' == 2 || a[i] - '0' == 5) {
        if (cnt[12])
          cnt[12]--;
        else
          goto res;
      } else if (a[i] - '0' == 6 || a[i] - '0' == 9) {
        if (cnt[16])
          cnt[16]--;
        else
          goto res;
      } else {
        if (cnt[a[i] - '0'])
          cnt[a[i] - '0']--;
        else
          goto res;
      }
    }
    cn++;
  }
res:
  cout << cn << endl;
}
