#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a[15], sum[15], i, ans;
  char str[210];
  scanf("%d%s", &t, str);
  memset(a, 0, sizeof(a));
  memset(sum, 0, sizeof(sum));
  while (t != 0) {
    a[t % 10]++;
    t /= 10;
  }
  for (i = 0; str[i] != '\0'; i++) sum[str[i] - '0']++;
  ans = 1000;
  a[6] += a[9];
  a[2] += a[5];
  sum[6] += sum[9];
  sum[2] += sum[5];
  for (i = 0; i < 9; i++)
    if (i != 5 && a[i] != 0) ans = min(ans, sum[i] / a[i]);
  printf("%d", ans);
  return 0;
}
