#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const long long MOD = 1e9 + 7;
long long modsum(long long i, long long j) {
  if (i + j >= MOD)
    return i + j - MOD;
  else
    return i + j;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N);
  for (ll i = 0; i < (N); ++i) cin >> S[i];
  vector<long long> T(M);
  for (ll i = 0; i < (M); ++i) cin >> T[i];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1, 0));
  dp[0][0] = 0;
  if (S[0] == T[0]) {
    dp[1][1] = 1;
  }
  for (ll j = 0; j < (M + 1); ++j)
    for (ll i = 0; i < (N); ++i) {
      dp[i + 1][j] = dp[i][j];
      for (ll k = (0); k < (j); ++k) {
        if (S[i] == T[k]) {
          dp[i + 1][j] = 1 + modsum(dp[i + 1][j], dp[i][k]);
        }
      }
    }
  cout << dp[N][M] + 1 << endl;
  return 0;
}
