#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  int *S, *T;
  long long max = 0, tmp;
  long long **dp, **sum;
  int imax = 0, jmax = 0;
  cin >> N >> M;
  S = new int[N];
  T = new int[M];
  sum = new long long *[N];
  dp = new long long *[N];
  for (int i = 0; i < N; i++) {
    sum[i] = new long long[M];
    dp[i] = new long long[M];
    cin >> S[i];
    sum[i][0] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    sum[0][i] = 0;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        tmp = 1;
        for (int ii = 0; ii < i; ii++) {
          for (int jj = 0; jj < j; jj++) {
            tmp = (tmp + dp[ii][jj]) % 1000000007;
          }
        }
        dp[i][j] = tmp;
        if (max < tmp) max = tmp;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  tmp = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      tmp = (tmp + dp[i][j]) % 1000000007;
    }
  }
  cout << (tmp + 1) << endl;
  return 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < M; j++) {
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] + sum[i - 1][j - 1] + dp[i][j]) %
          (1000000007);
    }
  }
  cout << sum[N - 1][M - 1] << endl;
  return 0;
}
