#include <bits/stdc++.h>
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;
const long long MOD = 1000000007;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n + 1);
  vector<long long> b(m + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
  }
  long long dp[n + 1][m + 1];
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= m; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
        if (a[i] == b[j]) {
          dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
        }
      }
    }
  }
  cout << dp[n][m] << endl;
  fflush(stdout);
  return 0;
}
