#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a[200005], b[200005], i, j, k, dp[2000][2000] = {0},
                                                 mod = 1e9 + 7;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      dp[i][j] = (mod + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % mod;
      if (a[i] == b[j]) dp[i][j] += (1 + dp[i - 1][j - 1] % mod) % mod;
    }
  }
  cout << (dp[n][m] + 1) % mod;
}
