#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
unsigned long long INF = 1000000007;
unsigned long long dp[2002][2002];
unsigned long long sdp[2002][2002];
int main() {
  memset(dp, 0, sizeof(dp));
  memset(sdp, 0, sizeof(sdp));
  int N, M;
  cin >> N >> M;
  vector<int> ls, lt;
  for (int i = 0; i < N; ++i) {
    int d;
    cin >> d;
    ls.push_back(d);
  }
  for (int i = 0; i < M; ++i) {
    int d;
    cin >> d;
    lt.push_back(d);
  }
  for (int n = 0; n < N; ++n) {
    unsigned long long s = ls[n];
    for (int m = 0; m < M; ++m) {
      unsigned long long t = lt[m];
      if (s == t) {
        dp[n][m] = 1;
        if (n > 0 && m > 0) dp[n][m] += sdp[n - 1][m - 1];
      }
      sdp[n][m] = dp[n][m];
      if (n > 0) sdp[n][m] += sdp[n - 1][m];
      if (m > 0) sdp[n][m] += sdp[n][m - 1];
      if (n > 0 && m > 0) sdp[n][m] -= sdp[n - 1][m - 1];
      if (sdp[n][m] > INF) sdp[n][m] %= INF;
    }
  }
  cout << (sdp[N - 1][M - 1] + 1) % INF << endl;
}
