#include <bits/stdc++.h>
using namespace std;
int convert(char ch) {
  int res = ch - 48;
  if (res == 9) res = 6;
  if (res == 5) res = 2;
  return res;
}
int main() {
  int total[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
  int need[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
  int x;
  cin >> x;
  while (x > 0) {
    int d = x % 10;
    if (d == 9) d = 6;
    if (d == 5) d = 2;
    need[d]++;
    x /= 10;
  }
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) total[convert(s[i])]++;
  int count = 0;
  bool f = true;
  while (f) {
    for (int i = 0; i < 9; ++i)
      if (total[i] >= need[i])
        total[i] -= need[i];
      else
        f = false;
    if (f) count++;
  }
  cout << count << endl;
  return 0;
}
