#include <bits/stdc++.h>
using namespace std;
int t, num[12], fnum[12], ans, i;
char c[1200];
int main() {
  scanf("%d", &t);
  scanf("%s", c + 1);
  for (i = strlen(c + 1); i >= 1; --i) num[c[i] - 48]++;
  for (; t; t /= 10) fnum[t % 10]++;
  ans = 10000000;
  for (i = 0; i <= 9; ++i)
    if (i != 2 && i != 5 && i != 6 && i != 9 && fnum[i])
      ans = min(ans, num[i] / fnum[i]);
  if (fnum[6] + fnum[9])
    ans = min(ans, (num[6] + num[9]) / (fnum[6] + fnum[9]));
  if (fnum[2] + fnum[5])
    ans = min(ans, (num[2] + num[5]) / (fnum[2] + fnum[5]));
  printf("%d\n", ans);
}
