#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;
long long dp[1005][1005];
long long sum[1005][1005];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n), B(m);
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 0; i < m; i++) cin >> B[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (A[i - 1] == B[j - 1])
        dp[i][j] = sum[i - 1][j - 1] + 1;
      else
        dp[i][j] = 0;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % Mod;
      if (sum[i][j] < 0) sum[i][j] += Mod;
    }
  cout << sum[n][m] + 1 << endl;
  return 0;
}
