#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int long long MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
int long long dp[2001][2001];
int main() {
  int long long n, m;
  cin >> n >> m;
  vector<int long long> s(n);
  vector<int long long> t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i + 1][j] + 1 + dp[i][j + 1];
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] += (dp[i][j + 1] - dp[i][j]);
        dp[i + 1][j + 1] += dp[i + 1][j];
        dp[i + 1][j + 1] %= MOD;
      }
    }
  }
  cout << (dp[n][m] + 1) % MOD << endl;
  return 0;
}
