#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<ll> s(n);
  vector<ll> t(m);
  for (int(i) = 0; (i) < (n); (i)++) cin >> s[i];
  for (int(j) = 0; (j) < (m); (j)++) cin >> t[j];
  ll dp[2001][2001] = {};
  for (int i = 0; i < 2001; i++) {
    dp[i][0] = dp[0][i] = 1LL;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m];
}
int main() {
  int T;
  T = 1;
  while (T--) {
    solve();
    cout << endl;
  }
}
