#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long n, m;
vector<long long> s, t;
long long dp[2010][2010];
bool vis[2010][2010];
long long solve(long long x, long long y) {
  if (vis[x][y]) return dp[x][y];
  vis[x][y] = true;
  if (x == 0 || y == 0) return dp[x][y] = 1;
  if (s[x - 1] == t[y - 1]) (dp[x][y] += (solve(x - 1, y - 1))) %= mod;
  (dp[x][y] += (solve(x - 1, y) + solve(x, y - 1) - solve(x - 1, y - 1))) %=
      mod;
  return dp[x][y];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  s.resize(n), t.resize(m);
  for (long long i = (0); i < (n); i++) cin >> s[i];
  for (long long i = (0); i < (m); i++) cin >> t[i];
  cout << solve(n, m) << endl;
}
