#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int cnt[100];
char s[500];
int has[100];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '2' || s[i] == '5') {
      cnt[2]++;
      continue;
    }
    if (s[i] == '6' || s[i] == '9') {
      cnt[6]++;
      continue;
    }
    cnt[s[i] - '0']++;
  }
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '2' || s[i] == '5') {
      has[2]++;
      continue;
    }
    if (s[i] == '6' || s[i] == '9') {
      has[6]++;
      continue;
    }
    has[s[i] - '0']++;
  }
  int ans = 99999;
  for (int i = 0; i < 10; i++) {
    if (i == '5' || i == '9') continue;
    if (cnt[i]) ans = min(ans, has[i] / cnt[i]);
  }
  cout << ans << endl;
  return 0;
}
