#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < (long long)(n); i++) cin >> s[i];
  for (long long i = 0; i < (long long)(m); i++) cin >> t[i];
  long long dp[2010][2010];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(m); j++) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
      if (s[i] == t[j])
        dp[i + 1][j + 1]++;
      else {
        dp[i + 1][j + 1] -= dp[i][j];
        dp[i + 1][j + 1] += MOD;
      }
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[n][m] + 1 << endl;
  return 0;
}
