#include <bits/stdc++.h>
using namespace std;
struct input {
  long long num;
  long long times;
  long long pre;
};
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  vector<vector<long long>> dp1(m + 1, vector<long long>(n + 1, 0));
  vector<vector<long long>> dp2(m + 1, vector<long long>(n + 1, 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] % 1000000007 + 1;
      } else {
        dp1[i + 1][j + 1] = 0;
      }
      dp1[i + 1][j + 1] %= 1000000007;
      dp2[i + 1][j + 1] %= 1000000007;
      dp2[i + 1][j + 1] =
          (dp2[i][j + 1] % 1000000007 + dp2[i + 1][j] % 1000000007) %
              1000000007 -
          dp2[i][j] % 1000000007 + dp1[i + 1][j + 1] % 1000000007;
      dp1[i + 1][j + 1] %= 1000000007;
      dp2[i + 1][j + 1] %= 1000000007;
    }
  }
  cout << (dp2[m][n] + 1) % 1000000007 << endl;
  return 0;
}
