#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200 + 10;
string a, b;
int cnt1[10], cnt2[10];
int CC = 0x3f3f3f3f;
int main() {
  cin >> a >> b;
  for (int i = 0; i < (int)a.size(); ++i) ++cnt1[a[i] - '0'];
  for (int i = 0; i < (int)b.size(); ++i) ++cnt2[b[i] - '0'];
  cnt1[2] += cnt1[5], cnt1[6] += cnt1[9];
  cnt2[2] += cnt2[5], cnt2[6] += cnt2[9];
  for (int i = 0; i < 10; ++i) {
    if (i == 5 || i == 9) continue;
    if (cnt1[i]) CC = min(CC, cnt2[i] / cnt1[i]);
  }
  cout << CC << endl;
  fclose(stdin);
  fclose(stdout);
  return 0;
}
