#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
long long N, M;
long long dp[2020][2020];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (int i = 0; i < (int)N; ++i) cin >> S[i];
  for (int j = 0; j < (int)M; ++j) cin >> T[j];
  for (int i = 0; i < (int)2020; ++i)
    for (int j = 0; j < (int)2020; ++j) dp[i][j] = 0;
  for (int i = 0; i < (int)N; ++i) {
    for (int j = 0; j < (int)M; ++j) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = 1 + dp[i + 1][j] + dp[i][j + 1];
        dp[i + 1][j + 1] %= mod;
      } else {
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
    }
  }
  cout << (dp[N][M] + 1) % mod << endl;
  return 0;
}
