#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
const int maxn = 2e3 + 10;
const int mod = 1e9 + 7;
long long dp[maxn][maxn];
int s[maxn], t[maxn], n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> t[i];
  for (int i = 0; i <= max(n, m); i++) dp[i][0] = dp[0][i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i] == t[j])
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
      else
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % mod;
  cout << dp[n][m] << '\n';
  return 0;
}
