#include <bits/stdc++.h>
using namespace std;
string a;
int long long na[9], nb[9];
int long long c = 10000000;
int main() {
  cin >> a;
  for (int x = 0; x < 9; x++) {
    na[x] = 0;
    nb[x] = 0;
  }
  for (int x = 0; x < a.length(); x++) {
    if (a[x] == '9') {
      na[6]++;
    } else if (a[x] == '5') {
      na[2]++;
    } else {
      na[a[x] - '0']++;
    }
  }
  cin >> a;
  for (int x = 0; x < a.length(); x++) {
    if (a[x] == '9') {
      nb[6]++;
    } else if (a[x] == '5') {
      nb[2]++;
    } else {
      nb[a[x] - '0']++;
    }
  }
  for (int x = 0; x < 9; x++) {
    if (na[x] > 0) {
      c = min(c, nb[x] / na[x]);
    }
  }
  cout << c << endl;
}
