#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 1e3 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const double INF = 1e9;
int casenum, casei;
int a[30], b[30], ans;
int len1, len2;
char s1[300], s2[300];
int main() {
  while (~scanf("%s%s", s1, s2)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    len1 = strlen(s1);
    len2 = strlen(s2);
    for (int i = 0; i < len1; i++) {
      a[s1[i] - '0']++;
    }
    a[2] += a[5];
    a[6] += a[9];
    a[5] = a[9] = 0;
    for (int i = 0; i < len2; i++) {
      b[s2[i] - '0']++;
    }
    b[2] += b[5];
    b[6] += b[9];
    b[5] = b[9] = 0;
    ans = INF;
    for (int i = 0; i <= 9; i++) {
      if (a[i]) gmin(ans, b[i] / a[i]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
