#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  vector<vector<long long>> dp(m + 10, vector<long long>(n + 10, 0));
  long long num = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[0]) {
      num++;
    }
    dp[1][i + 1] = num;
  }
  num = 1;
  for (int i = 0; i < m; i++) {
    if (s[0] == t[i]) {
      num++;
    }
    dp[i + 1][1] = num;
  }
  for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (s[j] == t[i]) {
        (dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]) %= MOD;
      } else {
        (dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) %= MOD;
      }
    }
  }
  cout << (dp[m][n]) % MOD << endl;
}
