#include <bits/stdc++.h>
using namespace std;
const int INF = ~(1 << 31);
const double pi = acos(-1);
const int EPS = 1e-9;
int n, m;
vector<int> A;
vector<int> B;
long long mem[10000][10000];
long long dp(int i, int j) {
  if (i == -1 || j == -1) {
    return 0;
  }
  if (mem[i][j] != -1) return mem[i][j];
  if (A[i] == B[j]) {
    return mem[i][j] = (dp(i - 1, j) + dp(i, j - 1) + 1) % 1000000007;
  } else {
    return mem[i][j] =
               (dp(i - 1, j) + dp(i, j - 1) - dp(i - 1, j - 1)) % 1000000007;
  }
}
int main() {
  cin.sync_with_stdio(false);
  memset(mem, -1, sizeof(mem));
  cin >> n >> m;
  A = vector<int>(n);
  B = vector<int>(m);
  for (long long i = (0); i < (n); ++i) cin >> A[i];
  for (long long i = (0); i < (m); ++i) cin >> B[i];
  cout << (dp(n, m) + 1) % 1000000007 << endl;
  return 0;
}
