#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using ll = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, lint>>>;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
const double PI = 3.1415926535897932;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};
void yes() { cout << "yes" << endl; }
void Yes() { cout << "Yes" << endl; }
void YES() { cout << "YES" << endl; }
void no() { cout << "no" << endl; }
void No() { cout << "No" << endl; }
void NO() { cout << "NO" << endl; }
void possible() { cout << "possible" << endl; }
void Possible() { cout << "Possible" << endl; }
void POSSIBLE() { cout << "POSSIBLE" << endl; }
void impossible() { cout << "impossible" << endl; }
void Impossible() { cout << "Impossible" << endl; }
void IMPOSSIBLE() { cout << "IMPOSSIBLE" << endl; }
int main() {
  lint n, m;
  cin >> n >> m;
  vector<lint> s(n);
  for (int i = 0; i < (n); i++) cin >> s[i];
  vector<lint> t(m);
  for (int i = 0; i < (m); i++) cin >> t[i];
  vector<vector<lint>> dp(n + 1, vector<lint>(m + 1, 0));
  dp[0][0] = 1;
  for (int j = 1; j <= m; j++) dp[0][j] += 1;
  for (int i = 1; i <= n; i++) dp[i][0] += 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
