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