#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
int n, m;
vector<int> s(2005), t(2005);
ll dp[2005][2005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (int i = (0), i_end_ = (n); i < i_end_; i++) cin >> s[i];
  for (int i = (0), i_end_ = (m); i < i_end_; i++) cin >> t[i];
  for (int i = (0), i_end_ = (n + 1); i < i_end_; i++) dp[i][0] = 1;
  for (int i = (0), i_end_ = (m + 1); i < i_end_; i++) dp[0][i] = 1;
  for (int i = (0), i_end_ = (n); i < i_end_; i++) {
    for (int j = (0), j_end_ = (m); j < j_end_; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
      } else {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
      }
    }
  }
  cout << dp[n][m] << "\n";
}
