#include <bits/stdc++.h>
using namespace std;
int ans, t[10], ok = 1;
char n[10], m[205];
int main() {
  cin >> n >> m;
  for (int i = 0; i < strlen(m); i++) {
    if (m[i] == '5')
      t[2]++;
    else if (m[i] == '9')
      t[6]++;
    else
      t[m[i] - '0']++;
  }
  while (ok) {
    for (int i = 0; i < strlen(n); i++) {
      if (n[i] == '5') {
        if (t[2] > 0)
          t[2]--;
        else
          ok = 0;
      } else if (n[i] == '9') {
        if (t[6] > 0)
          t[6]--;
        else
          ok = 0;
      } else {
        if (t[n[i] - '0'] > 0)
          t[n[i] - '0']--;
        else
          ok = 0;
      }
    }
    if (ok == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}
