package no329; import java.util.Scanner; public class Main { public static final long MOD = 1000000007; static long[] fact = Mod.factorialArray(1000, MOD); static long[] factInv = Mod.factorialInverseArray(1000, MOD, Mod.inverseArray(1000, MOD)); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] w = new int[n]; for(int i=0;i= w[j]) { int a = w[i]; int b = w[j]; if (a == b) { // System.out.println(i + "," + j + ":" + a + "->" + b + ":" + fact[a]); ans += fact[a]; }else{ long sum = 0; for(int k=0;k<=b;k++) { long x = comb(b,k) * Mod.pow(k, a, MOD); if ((b - k) % 2 == 0) { sum += x; }else{ sum += (MOD - x); } } // System.out.println(i + "," + j + ":" + a + "->" + b + ":" + sum % MOD); ans += sum; } } } } System.out.println(ans % MOD); } static long comb(int n,int r) { return fact[n] * factInv[r] % MOD * factInv[n-r] % MOD; } } class Mod { public static long[] factorialArray(int maxN,long mod) { long[] fact = new long[maxN+1]; fact[0] = 1 % mod; for(int i=1;i<=maxN;i++) { fact[i] = fact[i-1] * i % mod; } return fact; } public static long[] inverseArray(int maxN,long modP) { long[] inv = new long[maxN+1]; inv[1] = 1; for(int i=2;i<=maxN;i++) { inv[i] = modP - (modP / i) * inv[(int) (modP%i)] % modP; } return inv; } public static long[] factorialInverseArray(int maxN,long modP,long[] inverseArray) { long[] factInv = new long[maxN+1]; factInv[0] = 1; for(int i=1;i<=maxN;i++) { factInv[i] = factInv[i-1] * inverseArray[i] % modP; } return factInv; } public static long pow(long a,long n,long mod) { long res = 1; while(n > 0) { if ((n & 1) > 0) { res = (res * a) % mod; } a = (a * a) % mod; n/=2; } return res; } }