#include <bits/stdc++.h>
using namespace std;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr long long mod = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long dp[2010][2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  dp[0][0] = 1;
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> s[i];
    dp[i + 1][0] += dp[i][0];
  }
  for (int(i) = (0); (i) < (m); (i)++) {
    cin >> t[i];
    dp[0][i + 1] += dp[0][i];
  }
  for (int(i) = (0); (i) <= (n); (i)++)
    for (int(j) = (0); (j) <= (m); (j)++) {
      if (s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= mod;
      dp[i + 1][j + 1] += dp[i][j + 1];
      dp[i + 1][j + 1] %= mod;
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= mod;
      dp[i + 1][j + 1] -= dp[i][j];
      dp[i + 1][j + 1] %= mod;
    }
  cout << dp[n][m] << endl;
}
