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