#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long mod = 1e9 + 7;
long long dp[2003][2003];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[m + 1];
  long long i, j;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> b[i];
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      if (a[i] == b[j])
        dp[i][j] = (1 + 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] + 1ll) % mod;
  return 0;
}
