#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int N, M;
int s[2020], t[2020];
const long long mod = 1000000007;
long long sum[2020][2020];
long long dp[2020][2020];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> s[i];
  for (int i = 1; i <= M; i++) cin >> t[i];
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
        dp[i][j] %= mod;
        sum[i][j] =
            sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j];
        sum[i][j] %= mod;
      } else {
        dp[i][j] = 0;
        sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
        sum[i][j] %= mod;
      }
    }
  cout << (sum[N][M] + 1) % mod << endl;
}
