#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int req[10] = {};
  int val[10] = {};
  int twofiveNo = 0;
  int fivenineNo = 0;
  int reqtwofiveNo = 0;
  int reqfivenineNo = 0;
  for (int i = 0; i < a.length(); i++) {
    req[a[i] - '0'] += 1;
  }
  for (int i = 0; i < b.length(); i++) {
    val[b[i] - '0'] += 1;
  }
  bool check = true;
  int ans = 0;
  while (check) {
    for (int i = 0; i < 10; i++) {
      if (req[i] > 0) {
        if (i == 2 || i == 5) {
          if (val[2] + val[5] >= req[i]) {
            val[2] -= req[i];
          } else {
            cout << ans << endl;
            exit(0);
          }
        } else if (i == 6 || i == 9) {
          if (val[6] + val[9] >= req[i]) {
            val[6] -= req[i];
          } else {
            cout << ans << endl;
            exit(0);
          }
        } else if (val[i] >= req[i]) {
          val[i] -= req[i];
        } else {
          cout << ans << endl;
          exit(0);
        }
      }
    }
    ans += 1;
  }
  cout << ans << endl;
}
