#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int dp[1005][1005];
long long int mod = (1e9) + 7;
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long int arr[n + 1];
  long long int brr[m + 1];
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  for (long long int i = 1; i <= m; i++) cin >> brr[i];
  memset(dp, 0, sizeof(dp));
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (arr[i] == brr[j]) {
        dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
      } else {
        dp[i][j] =
            (-dp[i - 1][j - 1] + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
      }
    }
  }
  cout << (dp[n][m] + 1) % mod << '\n';
}
