#include <bits/stdc++.h>
using namespace std;
int a[20], b[20];
char s[110000];
int main() {
  int n, i, j;
  scanf("%s", s);
  for (i = 0; s[i]; i++) {
    if (s[i] == '5')
      a[2]++;
    else if (s[i] == '9')
      a[6]++;
    else
      a[s[i] - '0']++;
  }
  scanf("%s", s);
  for (i = 0; s[i]; i++) {
    if (s[i] == '5')
      b[2]++;
    else if (s[i] == '9')
      b[6]++;
    else
      b[s[i] - '0']++;
  }
  int ans = 210000;
  for (i = 0; i <= 9; i++)
    if (i - 9 && i - 5) {
      if (a[i]) ans = min(ans, b[i] / a[i]);
    }
  printf("%d\n", ans);
}
