#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e3 + 10;
const long long mod = 1e9 + 7;
long long pp[maxn][maxn];
long long a[maxn], b[maxn];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  for (long long i = 0; i < maxn; i++) {
    pp[i][0] = 1;
    pp[0][i] = 1;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (i != 0 && j != 0) {
        pp[i][j] = pp[i - 1][j] + pp[i][j - 1] - pp[i - 1][j - 1];
        if (a[i] == b[j]) pp[i][j] += pp[i - 1][j - 1];
      }
      if (i != 0 && j == 0) {
        pp[i][j] = pp[i - 1][j];
        if (a[i] == b[j]) pp[i][j]++;
      }
      if (i == 0 && j != 0) {
        pp[i][j] = pp[i][j - 1];
        if (a[i] == b[j]) pp[i][j]++;
      }
      if (i == 0 && j == 0) {
        if (a[i] == b[j]) pp[i][j]++;
      }
      pp[i][j] %= mod;
    }
  }
  cout << pp[n - 1][m - 1];
}
