#include <bits/stdc++.h>
using namespace std;
long long int sumTable[2010][2010];
long long int S[2010];
long long int T[2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= (int)(N); i++) {
    cin >> S[i];
  }
  for (int i = 1; i <= (int)(M); i++) {
    cin >> T[i];
  }
  sumTable[0][0] = 1;
  for (int i = 1; i <= (int)(N); i++) {
    sumTable[i][0] = 1;
  }
  for (int i = 1; i <= (int)(M); i++) {
    sumTable[0][i] = 1;
  }
  for (int i = 1; i <= (int)(N); i++) {
    for (int j = 1; j <= (int)(M); j++) {
      long long int val = 0;
      if (S[i] == T[j]) {
        val = sumTable[i - 1][j - 1];
      }
      sumTable[i][j] = (sumTable[i - 1][j] + sumTable[i][j - 1] -
                        sumTable[i - 1][j - 1] + val) %
                       1000000007;
    }
  }
  cout << sumTable[N][M] << "\n";
}
