#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;
long long dp[maxn][maxn], sum[maxn][maxn];
int n, m;
int s[maxn], t[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &t[i]);
  }
  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] = sum[i - 1][j - 1] + 1;
        dp[i][j] %= mod;
      } else
        dp[i][j] = 0;
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
      sum[i][j] %= mod;
    }
  }
  sum[n][m]++;
  sum[n][m] %= mod;
  cout << sum[n][m] << endl;
}
