#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long MOD = 1000000007;
const long long MAX = 400000;
int main() {
  int N, M;
  cin >> N >> M;
  int S[3000], T[3000];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    cout << i;
  }
  long long D[3000][3000];
  long long line[3000][3000];
  long long seq[3000][3000];
  long long sum[3000][3000];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (j == 0) {
        line[i][j] = 0;
      } else {
        line[i][j] = (line[i][j - 1] + D[i][j - 1]) % MOD;
      }
      if (i == 0) {
        seq[i][j] = 0;
      } else {
        seq[i][j] = (seq[i - 1][j] + D[i - 1][j]) % MOD;
      }
      if (i == 0 || j == 0) {
        sum[i][j] = 0;
      } else {
        sum[i][j] = (sum[i - 1][j - 1] + line[i - 1][j - 1] +
                     seq[i - 1][j - 1] + D[i - 1][j - 1]) %
                    MOD;
      }
      if (S[i] != T[j]) {
        D[i][j] = 0;
      } else {
        D[i][j] = sum[i][j] + 1;
      }
    }
  }
  cout << D[N - 1][M - 1];
  system("PAUSE");
}
