#include <bits/stdc++.h>
using namespace std;
int a[210];
int main() {
  string t;
  cin >> t;
  string x;
  cin >> x;
  int n = t.length();
  int ans = 0;
  while (1) {
    bool f;
    for (int i = 0; i < n; i++) {
      f = 0;
      int p = x.find(t[i]);
      if (p != string::npos)
        f = 1;
      else {
        if (t[i] == '2') {
          p = x.find('5');
          if (p != string::npos) f = 1;
        } else if (t[i] == '5') {
          p = x.find('2');
          if (p != string::npos) f = 1;
        } else if (t[i] == '6') {
          p = x.find('9');
          if (p != string::npos) f = 1;
        } else if (t[i] == '9') {
          p = x.find('6');
          if (p != string::npos) f = 1;
        }
      }
      if (!f) break;
      x = x.substr(0, p) + x.substr(p + 1);
    }
    if (!f)
      break;
    else
      ans++;
  }
  cout << ans << endl;
}
