#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;
int a[N], b[N];
long long dp[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + mod) % mod;
      if (a[i] == b[i]) {
        dp[i][j] = (dp[i][j] + 1 + dp[i - 1][j - 1]) % mod;
      }
    }
  }
  cout << (dp[n][m] + 1) % mod << '\n';
  return 0;
}
