#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int a[10] = {0};
  int b[10] = {0};
  int n = t;
  while (n > 0) {
    int r = n % 10;
    n = n / 10;
    if (r == 9) r = 6;
    if (r == 5) r = 2;
    a[r]++;
  }
  string str;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '9')
      b[6]++;
    else if (str[i] == '5')
      b[2]++;
    else
      b[str[i] - 48]++;
  }
  int ans = INT_MAX;
  for (int i = 0; i < 9; i++) {
    if (a[i] > 0) ans = min(ans, b[i] / a[i]);
  }
  cout << ans;
  return 0;
}
