#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10, mod = 1e9 + 7;
int n, m;
int s[maxn], t[maxn];
int dp[maxn][maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    dp[0][i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &t[i]);
    dp[i][0] = 1;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j])
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      else
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % mod;
    }
  printf("%d\n", (dp[n][m] % mod + mod) % mod);
  return 0;
}
