#include <bits/stdc++.h>
using namespace std;
char str[210], in[10];
int cnt[10], r[10];
int main() {
  scanf("%s %s", in, str);
  int l = strlen(in);
  for (int i = 0; i < l; i++) {
    if (in[i] == '9')
      cnt[6]++;
    else if (in[i] == '5')
      cnt[2]++;
    else
      cnt[in[i] - '0']++;
  }
  l = strlen(str);
  for (int i = 0; i < l; i++) {
    if (str[i] == '9')
      r[6]++;
    else if (str[i] == '5')
      r[2]++;
    else
      r[str[i] - '0']++;
  }
  int ans = 0x7fffffff;
  for (int i = 0; i <= 9; i++) {
    if (cnt[i] == 0) continue;
    ans = min(ans, r[i] / cnt[i]);
  }
  cout << ans << endl;
}
