#include <bits/stdc++.h>
using namespace std;
int main() {
  string t, s;
  cin >> t >> s;
  vector<int> s1(10);
  vector<int> t1(10);
  for (int i = 0; i < 10; i++) {
    s1[i] = 0;
    t1[i] = 0;
  }
  int n = s.length();
  for (int i = 0; i < n; i++) {
    s1[int(s[i]) - 48]++;
  }
  n = t.length();
  for (int i = 0; i < n; i++) {
    t1[int(t[i]) - 48]++;
  }
  s1[2] += s1[5];
  s1[5] = 0;
  s1[6] += s1[9];
  s1[9] = 0;
  t1[2] += t1[5];
  t1[5] = 0;
  t1[6] += t1[9];
  t1[9] = 0;
  int ans = 2000;
  for (int i = 0; i < 10; i++) {
    if (t1[i] > 0 && (s1[i] / t1[i]) < ans) ans = s1[i] / t1[i];
  }
  cout << ans << endl;
}
