#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 2005;
long long s[MAXN], t[MAXN], sum[MAXN][MAXN], dp[MAXN][MAXN];
void solve(int n) {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) sum[i][0] = 0;
  for (int i = 0; i <= m; i++) sum[0][i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
      } else
        dp[i][j] = 0;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  cout << (sum[n][m] + 1) % MOD;
  return 0;
}
