#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, t;
  cin >> s >> t;
  vector<int> cnt1(10);
  for (char x : s) {
    int it = x - '0';
    cnt1[it]++;
  }
  vector<int> cnt2(10);
  for (char x : t) {
    int it = x - '0';
    cnt2[it]++;
  }
  cnt1[2] += cnt1[5];
  cnt1[6] += cnt1[9];
  cnt1[5] = 0;
  cnt1[9] = 0;
  cnt2[2] += cnt2[5];
  cnt2[6] += cnt2[9];
  cnt2[5] = 0;
  cnt2[9] = 0;
  int ans = INT_MAX;
  for (int i = 0; i <= 9; ++i) {
    if (cnt1[i]) {
      int tmp = cnt2[i] / cnt1[i];
      ans = min(ans, tmp);
    }
  }
  cout << ans;
  return 0;
}
