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