#include <bits/stdc++.h>
using namespace std;
char t[10];
char digs[205];
int stats[10];
int stats2[10];
int main() {
  scanf("%s %s", t, digs);
  int i = 0;
  while (t[i] != 0) {
    if (t[i] == '5') t[i] = '2';
    if (t[i] == '9') t[i] = '6';
    stats[t[i] - '0']++;
    i++;
  }
  i = 0;
  while (digs[i] != 0) {
    if (digs[i] == '5') digs[i] = '2';
    if (digs[i] == '9') digs[i] = '6';
    stats2[digs[i] - '0']++;
    i++;
  }
  int min = 100000000;
  for (int i = 0; i < 10; i++) {
    if (stats[i] != 0) {
      if (stats2[i] / stats[i] < min) min = stats2[i] / stats[i];
    }
  }
  printf("%d\n", min);
  return 0;
}
