#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
ll dp[2005][2005];
void Main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (ll i = 0; i < (ll)(N); i++) cin >> S[i];
  for (ll i = 0; i < (ll)(M); i++) cin >> T[i];
  dp[0][0] = 1;
  for (ll i = 0; i < (ll)(2005); i++) dp[i][0] = 1;
  for (ll i = 0; i < (ll)(2005); i++) dp[0][i] = 1;
  for (ll i = 0; i < (ll)(N); i++) {
    for (ll j = 0; j < (ll)(M); j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1];
      } else {
        dp[i + 1][j + 1] += ((dp[i + 1][j] + dp[i][j + 1]) % MOD) - dp[i][j];
      }
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
