#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2100;
const int MOD = 1e9 + 7;
int n, m;
int second[MAXN], t[MAXN];
int dp[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) cin >> second[i];
  for (int i = (1); i <= (m); i++) cin >> t[i];
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) {
      if (second[i] == t[j])
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] + 1;
      else
        dp[i][j] = MOD + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  cout << ((dp[n][m] + 1) % MOD) << endl;
  return 0;
}
