#include <bits/stdc++.h>
using namespace std;
int main() {
  string t, s;
  cin >> t >> s;
  int n[10] = {0}, e[10] = {0};
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '5')
      n[2]++;
    else if (t[i] == '9')
      n[6]++;
    else
      n[t[i] - '0']++;
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '5')
      e[2]++;
    else if (s[i] == '9')
      e[6]++;
    else
      e[s[i] - '0']++;
  }
  int ans = (int)1e+9;
  for (int i = 0; i < 10; i++) {
    if (n[i] == 0) continue;
    ans = min(ans, e[i] / n[i]);
  }
  cout << ans;
  return 0;
}
