#include <bits/stdc++.h>
const int maxN = 2005;
const int MOD = 1000000007;
int ar[maxN], br[maxN];
long long int dp[maxN][maxN];
int n, m;
long long int serc(int a, int b) {
  if (a == n || b == m) {
    return 0;
  }
  if (dp[a][b] != -1) {
    return dp[a][b];
  }
  dp[a][b] = (ar[a] == br[b]) + serc(a + 1, b) + serc(a, b + 1) -
             (serc(a + 1, b + 1) * (1 - (ar[a] == br[b])));
  dp[a][b] %= MOD;
  return dp[a][b];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    for (int j = 0; j < m; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &br[i]);
  }
  printf("%lld\n", (1 + serc(0, 0)) % MOD);
  return 0;
}
