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