#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 200111;
const int inf = 1000000007;
const long long INF = 1e18;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int ddx[8] = {1, -1, 0, 0, 1, -1, -1, 1}, ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
void sosu(ll x, bool f[]) {
  ll y = x;
  for (ll i = 2; i <= sqrt(y); i++) {
    if (x % i == 0) {
      x /= i;
      f[i] = true;
      i--;
    }
  }
}
ll __gcd(ll x, ll y) {
  if (x < y) swap(x, y);
  while (1) {
    ll tmp = x % y;
    x = y;
    y = tmp;
    if (y == 0) break;
  }
  return x;
}
int main() {
  ll n, m, s[M], t[M];
  cin >> n >> m;
  ll dp[1001][1001] = {};
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n + 1; i++) dp[i][0] = 1;
  for (int j = 0; j < m; j++) cin >> t[j];
  for (int j = 0; j < m + 1; j++) dp[0][j] = 1;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      if (s[i - 1] == t[j - 1]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] = (dp[i][j] + inf) % inf;
    }
  }
  cout << dp[n][m] << endl;
}
