#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
ll INF = 1000000099;
ll dp[2100][2100];
signed main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> s(n, 0), t(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> t.at(i);
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      if (j > 0) dp[i][j] += dp[i][j - 1];
      if (i > 0) dp[i][j] += dp[i - 1][j];
      if (j > 0 && i > 0 && s[i - 1] == t[j - 1]) dp[i][j] += dp[i - 1][j - 1];
      if (j > 0 && i > 0) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] % mod << endl;
}
