#include <bits/stdc++.h>
using namespace std;
int main() {
  string t, s;
  int cnt_t[10], cnt_s[10];
  memset(cnt_t, 0, sizeof(cnt_t));
  memset(cnt_s, 0, sizeof(cnt_s));
  cin >> t;
  cin >> s;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '9') {
      t[i] = '6';
    }
    if (t[i] == '5') {
      t[i] = '2';
    }
    cnt_t[t[i] - '0']++;
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '9') {
      s[i] = '6';
    }
    if (s[i] == '5') {
      s[i] = '2';
    }
    cnt_s[s[i] - '0']++;
  }
  int ans = 1e9;
  for (int i = 0; i < 10; i++) {
    if (cnt_t[i] == 0) {
      continue;
    }
    ans = min(ans, cnt_s[i] / cnt_t[i]);
  }
  cout << ans;
  return 0;
}
