#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
static const int mod = 1000000007;
int dp[2020][2020];
int sum[2020][2020];
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  dp[0][0] = 1;
  sum[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    sum[0][i] = 1;
    sum[i][0] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = sum[i - 1][j - 1];
      }
      sum[i][j] = sum[i][j - 1];
      sum[i][j] %= mod;
      sum[i][j] += sum[i - 1][j];
      sum[i][j] %= mod;
      sum[i][j] -= sum[i - 1][j - 1];
      sum[i][j] %= mod;
      sum[i][j] += dp[i][j];
      sum[i][j] %= mod;
    }
  }
  cout << sum[n][m] << endl;
  return 0;
}
