#include <bits/stdc++.h>
int main(void) {
  char z[201], *p;
  const int H[] = {0, 1, 2, 3, 4, 2, 6, 7, 5, 6};
  int s = 999, n = 2, Q[2][8] = {};
  while (n--)
    for (gets(p = z); *p; ++Q[n][H[*p++ - '0']])
      ;
  while (s && 8 ^ ++n)
    if (Q[1][n]) s = std::min(s, Q[0][n] / Q[1][n]);
  printf("%d", s);
  return 0;
}
