#include <bits/stdc++.h>
using namespace std;
int main() {
  string T, S;
  while (cin >> T >> S) {
    int Ti[10], Pic[10], i, j, k, Min = -1, Max;
    memset(Ti, 0, sizeof(Ti));
    memset(Pic, false, sizeof(Pic));
    for (i = 0; i < S.size(); i++) {
      S[i] -= 48;
      if (S[i] == 5)
        Pic[2]++;
      else if (S[i] == 9)
        Pic[6]++;
      else
        Pic[int(S[i])]++;
    }
    for (i = 0; i < T.size(); i++) {
      T[i] -= 48;
      if (T[i] == 5)
        Ti[2]++;
      else if (T[i] == 9)
        Ti[6]++;
      else
        Ti[int(T[i])]++;
    }
    for (i = 0; i < 10; i++) {
      if (Ti[i] != 0 && Pic[i] != 0 && (Min > Pic[i] / Ti[i] || Min == -1))
        Min = Pic[i] / Ti[i];
    }
    cout << Min << endl;
  }
}
