#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long dp[2005][2005];
vector<int> v1, v2;
int n, m;
long long f(int n1, int n2) {
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n1; i++) {
    for (int j = 1; j <= n2; j++) {
      if (v1[i - 1] == v2[j - 1])
        dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
      else
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  return dp[n1][n2] + 1;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    v1.push_back(in);
  }
  for (int i = 0; i < m; i++) {
    int in;
    cin >> in;
    v2.push_back(in);
  }
  memset(dp, -1, sizeof(dp));
  cout << f(n, m) % MOD << endl;
  return 0;
}
