#include <bits/stdc++.h>
using namespace std;
string t;
string g;
int T[10];
int G[10];
int res;
void read() {
  int i;
  cin >> t >> g;
  for (i = 0; i < t.size(); i++) T[t[i] - '0']++;
  for (i = 0; i < g.size(); i++) {
    if (g[i] == '6' or g[i] == '9')
      G[6]++, G[9]++;
    else if (g[i] == '2' or g[i] == '5')
      G[2]++, G[5]++;
    else
      G[g[i] - '0']++;
  }
}
void solve() {
  int i;
  bool b = 1, k = 1;
  while (1) {
    b = k = 1;
    for (i = 0; i < 10; i++) {
      if (i == 2 or i == 5) {
        G[2] -= T[i];
        G[5] -= T[i];
        if (G[2] < 0 or G[5] < 0) return;
      }
      if (i == 6 or i == 9) {
        G[6] -= T[i];
        G[9] -= T[i];
        if (G[6] < 0 or G[9] < 0) return;
      } else if (i != 2 and i != 5 and i != 6 and i != 9) {
        G[i] -= T[i];
        if (G[i] < 0) return;
      }
    }
    res++;
  }
}
int main() {
  read();
  solve();
  cout << res << endl;
}
