#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
long long a[2003], b[2003];
long long dp[2003][2003];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= m; j++) cin >> b[j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % 1000000007;
      if (a[i] == b[j])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % 1000000007;
    }
  cout << dp[n][m] + 1;
}
