#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793;
int a[10];
int b[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '2' or t[i] == '5') {
      a[5]++;
      a[2]++;
    } else if (t[i] == '6' or t[i] == '9') {
      a[6]++;
      a[9]++;
    } else {
      a[t[i] - '0']++;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '2' or s[i] == '5') {
      b[5]++;
      b[2]++;
    } else if (s[i] == '6' or s[i] == '9') {
      b[6]++;
      b[9]++;
    } else {
      b[s[i] - '0']++;
    }
  }
  int ans = 0;
  int x = 0;
  for (int i = 0; i < 10; i++) {
    if (b[i] and x)
      ans = min(a[i] / b[i], ans);
    else if (b[i]) {
      ans = a[i] / b[i];
      x = 1;
    }
  }
  cout << ans;
  return 0;
}
