#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1e9 + 7;
template <typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}
template <typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}
void addmod(long long& a, long long b) { a = (a + b) % MOD; }
template <typename T>
void dumpContents(const T& v, const string& msg) {
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
  }
} before_main_function;
constexpr int N_MAX = 2e3;
long long dp[N_MAX][N_MAX] = {{0}};
long long sum[N_MAX][N_MAX] = {{0}};
int N, M;
void dump() {
  for (int j = 0; j < M; j++) {
    cerr << "j " << j << ": ";
    for (int i = 0; i < N; i++) {
      cerr << " " << sum[i][j];
    }
    cerr << "\n";
  }
}
int main(int argc, char** argv) {
  cin >> N >> M;
  vector<int> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  vector<int> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  for (int i = 0; i < N; i++) {
    if (S[i] == T[0]) {
      dp[i][0] = 1;
      sum[i][0] = 1;
    }
  }
  for (int j = 0; j < M; j++) {
    if (S[0] == T[j]) {
      dp[0][j] = 1;
      sum[0][j] = 1;
    }
  }
  for (int j = 0; j < M; j++) {
    for (int i = 1; i < N; i++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < M; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < M; j++) {
      if (S[i] == T[j]) {
        addmod(dp[i][j], sum[i - 1][j - 1] + 1);
      }
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  cout << sum[N - 1][M - 1] + 1 << "\n";
  return 0;
}
