#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int N = 51;
ll dp[N][2], vis[N][2];
ll repx[N], a[N];
ll n, x;
// question is we have to find number A such that (x+A) has no common coin with A
// i represent ith type of coin and f represent we have carry or not from previous
ll fun(int i, int f) {
    // if f == 1 then we get carry for i-1 to ith bit
    // if f == 0 then we don't get any carry for ith from back
    if(i == n-1) return 1; 

    // if we already know ans for current state then we return that directly 
    if(vis[i][f] == 1) return dp[i][f];

    vis[i][f] = 1;

    // cur-1 represent in any representation maximum number of coin, we can take of that type
    int cur = a[i+1]/a[i];

    // repx[i] + f == cur it means all the coin of ith type change
    // in (i+1)th type we genrate a carry for i+1 th bit 
    if(cur == repx[i] + f)  {
        // We can't put any bit here in A think why
        dp[i][f] = fun(i+1, 1);
    }
    else {
        // if there is some coin of ith type or we get any carry from previous in (x+A) 
        // then  there is two way to take coin of ith type in A
        // 1st we take as much coin such that in (x+A) there are total number of coin of ith type
        // becomes equal to cur so that we can change ith type of coin in (x+A) to (i+1)th type  coin
        // this is same that we get carry from previous 
        if(repx[i] + f > 0) {
            dp[i][f] = fun(i+1, 1);
        }
        //2nd we don't put any coin of ith type in A
        dp[i][f] += fun(i+1, 0);
    }
    return dp[i][f];
}

void solve() {
    cin >> n >> x;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = n-1; i >= 0; i--) {
        repx[i] = x/a[i];
        x %= a[i];
    }
    // at 0 there is no previous carry
    cout << fun(0, 0) << endl;
}

int main()
{
	solve();
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll dp[1005][1005];
ll A[1005], B[1005];

int main2() {
  int N = nextLong();
  int M = nextLong();
  REP(i, N) A[i] = nextLong();
  REP(i, M) B[i] = nextLong();

  const ll INF = 1LL << 61;
  REP(i, N+1) REP(j, M+1) dp[i][j] = INF;

  dp[0][0] = 0;
  REP(i, N+1) {
    REP(j, M+1) {
      chmin(dp[i+1][j], dp[i][j] + 1);
      chmin(dp[i][j+1], dp[i][j] + 1);
      chmin(dp[i+1][j+1], dp[i][j] + (A[i] == B[j] ? 0 : 1));
    }
  }


  ll ans = dp[N][M];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}