#include <bits/stdc++.h>
using namespace std;
long long dp[2007][2007];
long long a[2007];
long long b[2007];
int n, m;
long long fun(int i, int j) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  long long one = fun(i + 1, j) - fun(i + 1, j + 1);
  long long two = fun(i, j + 1) - fun(i + 1, j + 1);
  one = (one + (long long)(1e9 + 7)) % (long long)(1e9 + 7);
  two = (two + (long long)(1e9 + 7)) % (long long)(1e9 + 7);
  dp[i][j] = (one + two + fun(i + 1, j + 1)) % (long long)(1e9 + 7);
  if (a[i] == b[j]) {
    dp[i][j] = (dp[i][j] + 1 + fun(i + 1, j + 1)) % (long long)(1e9 + 7);
  }
  cout << i << " " << j << " : " << dp[i][j] << "\n";
  return dp[i][j];
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long j = 0; j < m; j++) {
    cin >> b[j];
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      dp[i][j] = -1;
    }
  }
  cout << (fun(0, 0) + 1) % (long long)(1e9 + 7) << "\n";
  return 0;
}
