#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;
int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  vector<ll> S(N);
  for (ll i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  vector<ll> T(M);
  for (ll i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  ll result = 0;
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
  for (ll i = 0; i <= N; i++) {
    dp[i][0] = 1;
  }
  for (ll i = 0; i <= M; i++) {
    dp[0][i] = 1;
  }
  for (ll j = 1; j <= M; j++) {
    for (ll i = 1; i <= N; i++) {
      ll iS = i - 1;
      ll iT = j - 1;
      if (S[iS] == T[iT]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
        dp[i][j] %= MOD;
      }
    }
  }
  printf("%lld\n", dp[N][M]);
}
