inputs = (gets).split(" ")
$nn = inputs[0].to_i
xx = inputs[1].to_i

inputs = (gets).split(" ")
$si = inputs.map{|istr| istr.to_i}
$si2 = $si

$selected = []
$total = 0

def fact(n)
  r = n
  (n-1).downto(1) do |a|
    r = r*a
  end
  if (r==0) then
      r = 1
  end
  return r
end
#puts fact(3)

def mod_ope(b, na)
  #p $si
  if b < $si2.min || $selected.length == $nn then
  #if $selected.length == $nn then
    #p $selected
    #puts "#{b} / #{na} / #{$selected.length}"
    #puts "#{b}"
    $total = $total + b*fact($nn-$selected.length)
    $selected.delete(na)
    return true
  end
  ($nn).times do |n2|
    n = n2.modulo($nn)
    if not $selected.include?(n) then
      #puts "=> #{n}"
      $selected.push(n)
      $si2.delete($si[n])
      mod_ope(b.modulo($si[n]), n)
      $si2.push($si[n])
    end
  end
  $selected.delete(na)
  return false
end

$nn.times do |n|
  black = xx
  $selected = [n]
  $si2 = $si.dup
  $si2.delete($si[n])
  $si2.push(100001)
  mod_ope(xx.modulo($si[n]), n)
end

puts $total.modulo(1000000000+7)