#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long dp[2001][2001];
long long mod = 1e9 + 7;
long long CommomSubsequencesCount(vector<int> &s, vector<int> &t) {
  int n1 = s.size();
  int n2 = t.size();
  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 (s[i - 1] == t[j - 1]) {
        dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
        dp[i][j] %= mod;
      } 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] % mod;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a, b;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    int u;
    cin >> u;
    a.push_back(u);
  }
  for (int i = 0; i < m; i++) {
    int u;
    cin >> u;
    b.push_back(u);
  }
  cout << (CommomSubsequencesCount(a, b) + 1) % mod << '\n';
}
