#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
const int N = 2e3 + 5;
const int MOD = 1e9 + 7;
int s[N], t[N], n, m;
long long dp[N][N], S[N][N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  for (int i = 1; i <= m; ++i) scanf("%d", &t[i]);
  S[0][0] = 1;
  for (int i = 1; i <= n; ++i) S[0][i] = S[i][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = S[i - 1][j - 1] % MOD;
      }
    }
    for (int j = 1; j <= m; ++j) {
      S[i][j] = (S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  printf("%lld\n", (S[n][m] + MOD) % MOD);
  return 0;
}
