#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
template <class T>
inline void chmax(T &a, const T &b) {
  if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
  if ((a) > (b)) (a) = (b);
}
template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
long long dp[1001][1001];
long long solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n + 1, -1);
  vector<long long> t(m + 1, -1);
  for (long long i = (long long)(0); i < (long long)(n); ++i) cin >> s[i + 1];
  for (long long i = (long long)(0); i < (long long)(m); ++i) cin >> t[i + 1];
  42;
  for (long long j = (long long)(0); j < (long long)(m + 1); ++j) dp[0][j] = 1;
  long long res = 0;
  for (long long i = (long long)(1); i < (long long)(n + 1); ++i) {
    for (long long j = (long long)(0); j < (long long)(m + 1); ++j) {
      dp[i][j] += dp[i][j - 1];
      if (s[i] == t[j]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
    for (long long j = (long long)(0); j < (long long)(m + 1); ++j) {
      dp[i][j] += dp[i - 1][j];
    }
  }
  42;
  cout << dp[n][m] % MOD << endl;
  return 0;
}
signed main() {
  solve();
  return 0;
}
