#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int ans = 9999;
  int pa[10] = {0}, pb[10] = {0};
  cin >> a >> b;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == '5') {
      a[i] = '2';
    }
    if (a[i] == '9') {
      a[i] = '6';
    }
    pa[a[i] - '0']++;
  }
  for (int i = 0; i < b.length(); i++) {
    if (b[i] == '5') {
      b[i] = '2';
    }
    if (b[i] == '9') {
      b[i] = '6';
    }
    pb[b[i] - '0']++;
  }
  for (int i = 0; i < 10; i++) {
    if (pa[i] > 0 && pb[i] > 0) {
      if (pb[i] / pa[i] < ans) {
        ans = pb[i] / pa[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
