#include <bits/stdc++.h>
int main() {
  char ch[222];
  int a[10] = {0}, b[10] = {0};
  int sum = 0, i;
  scanf("%s", ch);
  for (i = 0; i < strlen(ch); i++) {
    if (ch[i] - '0' == 5)
      a[2]++;
    else if (ch[i] - '0' == 9)
      a[6]++;
    else
      a[(ch[i] - '0')]++;
  }
  scanf("%s", ch);
  for (i = 0; i < strlen(ch); i++) {
    if (ch[i] - '0' == 5)
      b[2]++;
    else if (ch[i] - '0' == 9)
      b[6]++;
    else
      b[(ch[i] - '0')]++;
  }
  int sign = 1;
  while (sign) {
    for (i = 0; i < 10; i++) {
      if (b[i] - a[i] >= 0) {
        b[i] -= a[i];
        continue;
      } else {
        sign = 0;
        break;
      }
    }
    if (i == 10) sum++;
  }
  printf("%d\n", sum);
  return 0;
}
