#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[20], b[20], ans = 1e9;
  char c[100010], d[100010];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> c >> d;
  for (int i = 0; i < strlen(c); i++) a[c[i] - '0']++;
  a[6] += a[9];
  a[2] += a[5];
  for (int i = 0; i < strlen(d); i++) {
    if (d[i] == '9' || d[i] == '6') {
      b[6]++;
      b[9]++;
    } else if (d[i] == '2' || d[i] == '5') {
      b[2]++;
      b[5]++;
    } else
      b[d[i] - '0']++;
  }
  for (int i = 0; i < 10; i++)
    if (a[i] > 0 && i != 5 && i != 9) ans = min(ans, b[i] / a[i]);
  cout << ans << endl;
  return 0;
}
