#include <bits/stdc++.h>
using namespace std;
int occ[2][10];
int main() {
  string a, b;
  cin >> a;
  cin >> b;
  for (int i = 0; i < a.size(); i++) {
    occ[0][a[i] - '0']++;
  }
  for (int i = 0; i < b.size(); i++) {
    occ[1][b[i] - '0']++;
  }
  for (int k = 0; k < 2; k++) {
    occ[k][2] += occ[k][5];
    occ[k][5] = 0;
    occ[k][6] += occ[k][9];
    occ[k][9] = 0;
  }
  int can = 100000000;
  for (int d = 0; d < 10; d++) {
    if (occ[0][d] != 0) can = min(can, occ[1][d] / occ[0][d]);
  }
  cout << can << "\n";
  return 0;
}
