#include <bits/stdc++.h>
using namespace std;
long long x, y, a[2003], b[2003], dp[2003][2003], m[2003][2003], s = 1;
int main() {
  cin >> x >> y;
  m[0][0] = 1;
  for (int i = 1; i <= x; i++) cin >> a[i], m[i][0] = 1;
  for (int j = 1; j <= y; j++) cin >> b[j], m[0][j] = 1;
  for (int i = 1; i <= x; i++)
    for (int j = 1; j <= y; j++) {
      if (a[i] == b[j]) dp[i][j] = (dp[i][j] + m[i - 1][j - 1]) % 1000000007;
      m[i][j] =
          (m[i][j - 1] + m[i - 1][j] - m[i - 1][j - 1] + dp[i][j]) % 1000000007;
      s = (s + dp[i][j]) % 1000000007;
    }
  cout << s;
  return 0;
}
