#include <bits/stdc++.h>
using namespace std;
int main() {
  string x, y;
  cin >> x >> y;
  int a[10] = {0};
  int b[10] = {0};
  for (int i = 0; i < y.size(); i++) {
    if (y[i] == '2' || y[i] == '5')
      a[2]++;
    else if (y[i] == '6' || y[i] == '9')
      a[6]++;
    else
      a[y[i] - 48]++;
  }
  int ans = INT_MAX;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == '2' || x[i] == '5')
      b[2]++;
    else if (x[i] == '6' || x[i] == '9')
      b[6]++;
    else
      b[x[i] - 48]++;
  }
  for (int i = 0; i < 10; i++)
    if (b[i]) ans = min(ans, a[i] / b[i]);
  cout << ans;
}
