#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
ll const mod = 1e9 + 7;
const ll MAX = 1000005;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll dp[2005][2005];
int main() {
  int n, m;
  cin >> n >> m;
  vi 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];
  for (long long i = 0; i < n + 1; ++i) dp[i][0] = 1;
  for (long long i = 0; i < m + 1; ++i) dp[0][i] = 1;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      dp[i + 1][j + 1] %= mod;
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
