#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
constexpr ll mod = 1000000007;

ll N, M;
ll S[2010], T[2010];
ll dp[2010][2010], sum[2010][2010];

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, N )
    scanf( "%lld", S+i );
  rep( i, M )
    scanf( "%lld", T+i );

  rep( i, N ) rep( j, M )
  {
    if( S[i] == T[j] )
      dp[i+1][j+1] = (sum[i][j]+1)%mod;

    sum[i+1][j+1] = (((sum[i+1][j]+sum[i][j+1])%mod-sum[i][j]+mod)%mod+dp[i+1][j+1])%mod;
  }

  printf( "%lld\n", (sum[N][M]+1)%mod );

  return 0;
}