#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// ユークリッドの互除法で最大公約数を求める
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
// 最小公倍数
int lcm(int a,int b){
  return a/gcd(a,b)*b;
}
int main()
{
  int n; cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  int mn = inf;
  rep(i,n) {
    chmin(mn, a[i]);
  }

  map<int,int> mp;
  rep(tmp,n) {
    for(int i = 1; i*i <= a[tmp]; ++i) {
      if(a[tmp] % i == 0) {
        if(mp[i] == 0) mp[i] = a[tmp];
        else mp[i] = gcd(mp[i], a[tmp]);
        if(a[tmp]/i!=i) {
          int j = a[tmp]/i;
          if(mp[j] == 0) mp[j] = a[tmp];
          else mp[j] = gcd(mp[j], a[tmp]);          
        }
      }
    }
  }

  int res = 0;
  for(auto tmp: mp) {
    auto [key, val] = tmp;
    if(mn >= key && key == val) res++;
  }
  cout << res << "\n";

  return 0;
}

/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int N = 1e3 + 5;
int a[N], b[N];
int n, m;
int dp[N][N];
int dfs(int i, int j) {
	if (i > n) {
		return m - j + 1;
	} else if (j > m) {
		return  n - i + 1;
	}
	if (dp[i][j] != -1) return dp[i][j];
	int ret = inf;
	if (a[i] == b[j]) {
		ret = min(ret, dfs(i + 1, j + 1));
	}
	int op = 1 + min({dfs(i + 1, j), dfs(i, j + 1), dfs(i + 1, j + 1)});
	ret = min(ret, op);
	return dp[i][j] = ret;
}
void solve() {
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int j = 1; j <= m; j++) cin >> b[j];
	cout << dfs(0, 0) << endl;
}
int32_t main()
{
	zanj0();
	solve();
	return 0;
}