#include <bits/stdc++.h>
using namespace std;
int n, m, mod = 1000000007;
vector<int> s(1e3 + 3), t(1e3 + 3);
long long dp[1003][1003];
long long solve(int i, int j) {
  if (i == 0 || j == 0) {
    return 1;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  dp[i][j] = 0;
  if (s[i] == t[j]) {
    dp[i][j] += solve(i - 1, j - 1);
  }
  dp[i][j] += solve(i - 1, j) + solve(i, j - 1) - solve(i - 1, j - 1);
  dp[i][j] += mod;
  dp[i][j] %= mod;
  return dp[i][j];
}
int main(void) {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> t[i];
  }
  cout << solve(n, m) << "\n";
  return 0;
}
