#include <bits/stdc++.h>
using namespace std;
int main() {
  char Inpot[10];
  char Example[220];
  int Inpot_num[10], Example_num[10];
  while (scanf("%s", Inpot) != EOF) {
    memset(Inpot_num, 0, sizeof(Inpot_num));
    memset(Example_num, 0, sizeof(Example_num));
    scanf("%s", Example);
    int In_len = strlen(Inpot), Exa_len = strlen(Example);
    for (int i = 0; i < In_len; i++) Inpot_num[Inpot[i] - '0']++;
    for (int i = 0; i < Exa_len; i++) Example_num[Example[i] - '0']++;
    Inpot_num[2] += Inpot_num[5];
    Inpot_num[6] += Inpot_num[9];
    Inpot_num[5] = Inpot_num[9] = 0;
    Example_num[2] += Example_num[5];
    Example_num[6] += Example_num[9];
    Example_num[5] = Example_num[9] = 0;
    int ans = 99999;
    for (int i = 0; i < 10; i++)
      if (Inpot_num[i]) {
        ans = min(ans, Example_num[i] / Inpot_num[i]);
      }
    if (ans == 99999) ans = 0;
    printf("%d\n", ans);
  }
  return 0;
}
