/*input
3 3
1 2 3
1 2 3
*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;
vector < int > v1, v2;
ll dp[2005][2005];

ll func(int n, int m)
{
  if(n <= 0 or m <= 0) {
    return 0;
  }
  if(dp[n][m] > -1) {
    return dp[n][m];
  }
  ll res = 0;
  if(v1[n - 1] == v2[m - 1]) {
    res = 1 + func(n - 1, m) + func(n, m - 1);
    res %= MOD;
  } else {
    res = func(n - 1, m) + func(n, m - 1) - func(n - 1, m - 1);
    res %= MOD;
  }
  return dp[n][m] = res;
}

int main()
{
  ifalse;
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i ++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  for(int j = 0; j < m; j ++) {
    int x;
    cin >> x;
    v2.push_back(x);
  }
  memset(dp, -1, sizeof(dp));
  cout << func(n, m) + 1;
  return 0;
}