#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int MOOD = 998244353;
using namespace std;
long long dp[2001][2001];
int flag[2001][2001];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1), t(m + 1);
  for (int i = 1; i <= n; i++) cin >> s[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 (s[i] == t[j]) flag[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) dp[i][1] = dp[i - 1][1] + flag[i][1];
  for (int j = 1; j <= m; j++) dp[1][j] = dp[1][j - 1] + flag[1][j];
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + dp[i - 1][j - 1] * flag[i][j] -
                 dp[i - 1][j - 1] + flag[i][j];
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[n][m] + 1) % MOD << endl;
  return 0;
}
