#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 memo[2005][2005];
ll dfs(int i, int j) {
  if (i < 0 || j < 0) return 1;
  if (memo[i][j] != 0) return memo[i][j];
  if (s[i] == t[j]) {
    memo[i][j] = (dfs(i, j - 1) + dfs(i - 1, j)) % MOD;
  } else {
    memo[i][j] = (dfs(i, j - 1) + dfs(i - 1, j) - dfs(i - 1, j - 1)) % MOD;
  }
  return memo[i][j];
}
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];
  cout << dfs(n - 1, m - 1) << "\n";
}
