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