<?php
fscanf(STDIN, "%d %d", $N, $M);
$sArray = explode(" ", trim(fgets(STDIN)));
$tArray = explode(" ", trim(fgets(STDIN)));
$count=0;
$ss =array();
for($i=0;$i<$N+1;$i++){
    $sstr="";
    $bit = str_pad(decbin($i), $N, '0', STR_PAD_LEFT);
    for($j=0;$j<$N;$j++){
      if(strcmp($bit[$j],"1")==0){
        $sstr = $sstr.$sArray[$j].",";
      }
    }
    $ss[]=$sstr;
}
for($i=0;$i<$M+1;$i++){
    $sstr="";
    $bit = str_pad(decbin($i), $M, '0', STR_PAD_LEFT);
    for($j=0;$j<$M;$j++){
      if(strcmp($bit[$j],"1")==0){
        $sstr = $sstr.$tArray[$j].",";
      }
    }
      $count=($count+count(array_keys($ss,$sstr)))%100000007;
}

  echo  $count."\n";
?>