#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  long long* dp1[2005];
  long long* dp2[2005];
  for (int i = 0; i < 2005; i++) {
    dp1[i] = (long long*)malloc(sizeof(long long) * 2005);
    dp2[i] = (long long*)malloc(sizeof(long long) * 2005);
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> t[j];
  }
  for (int i = 0; i < 2005; i++) {
    for (int j = 0; j < 2005; j++) {
      dp1[i][j] = 0;
      dp2[i][j] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (s[j] == t[i]) {
        dp1[i + 1][j + 1] = (dp2[i][j] + 1) % 1000000007;
      } else {
        dp1[i + 1][j + 1] = 0;
      }
      dp1[i + 1][j + 1] %= 1000000007;
      dp2[i + 1][j + 1] = (dp2[i][j + 1] + dp2[i + 1][j]) % 1000000007 -
                          (dp2[i][j]) % 1000000007 +
                          (dp1[i + 1][j + 1]) % 1000000007;
      dp2[i + 1][j + 1] %= 1000000007;
    }
  }
  cout << (dp2[m][n] + 1) % 1000000007 << endl;
  return 0;
}
