#include <bits/stdc++.h>
using namespace std;
long long bx[] = {0, 0, 1, -1, 1, -1, -1, 1};
long long by[] = {1, -1, 0, 0, 1, -1, 1, -1};
long long dp[3001][3001];
long long n, m;
void CommonSubsequence(long long *A, long long *B) {
  memset(dp, 0, sizeof dp);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (A[i - 1] == B[j - 1]) {
        dp[i][j] = (1 + dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      } else {
        dp[i][j] =
            (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  long long s[n], t[m];
  for (long long i = 0; i <= n - 1; ++i) cin >> s[i];
  for (long long i = 0; i <= m - 1; ++i) cin >> t[i];
  CommonSubsequence(s, t);
  cout << (dp[n][m] + 1) % 1000000007;
  return 0;
}
