#include <bits/stdc++.h>
using namespace std;
int main() {
  string p, q;
  cin >> p >> q;
  for (int i = 0; i < p.length(); i++) {
    if (p[i] == '2') p[i] = '5';
    if (p[i] == '6') p[i] = '9';
  }
  for (int i = 0; i < q.length(); i++) {
    if (q[i] == '2') q[i] = '5';
    if (q[i] == '6') q[i] = '9';
  }
  int a[10] = {0}, b[10] = {0};
  for (int i = 0; i < p.length(); i++) a[p[i] - '0']++;
  for (int i = 0; i < q.length(); i++) b[q[i] - '0']++;
  int count = INT_MAX;
  for (int i = 0; i < 10; i++) {
    if (a[i]) count = min(count, b[i] / a[i]);
  }
  cout << count << endl;
  return 0;
}
