#include <bits/stdc++.h>
using namespace std;
int freq[10], need[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int cnt = 0, ok = 1;
  string t, s;
  cin >> t >> s;
  for (int i = 0; i < s.length(); ++i) {
    ++freq[s[i] - '0'];
  }
  while (ok) {
    for (int i = 0; i < t.length(); ++i) {
      if (t[i] == '2' || t[i] == '5') {
        if (freq[2]) {
          --freq[2];
          continue;
        }
        if (freq[5]) {
          --freq[5];
          continue;
        }
        ok = 0;
        break;
      } else if (t[i] == '6' || t[i] == '9') {
        if (freq[6]) {
          --freq[6];
          continue;
        }
        if (freq[9]) {
          --freq[9];
          continue;
        }
        ok = 0;
        break;
      } else if (freq[t[i] - '0']) {
        --freq[t[i] - '0'];
      } else {
        ok = 0;
      }
    }
    if (ok) ++cnt;
  }
  cout << cnt << "\n";
  return 0;
}
