Problem:
Score : 1000 points

Problem Statement

There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.

Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.

The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.

Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?

Constraints

2≦N≦300

1≦M≦300

Input

The input is given from Standard Input in the following format:

N M

Output

Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).

Sample Input 1

3 3

Sample Output 1

2

As shown below, the condition is satisfied only when c = (2,3,1) or c = (3,2,1). Sequences such as c = (2,3,2), c = (2,1,3), c = (1,2,2) do not satisfy the condition.

Sample Input 2

150 300

Sample Output 2

734286322

Sample Input 3

300 150

Sample Output 3

0

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,M;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long[,,] d = new long[M+1,N,N+1];
        for(int i=0;i<M+1;i++){
            for(int j=0;j<N;j++){
                for(int k=0;k<N+1;k++){
                    if(i == 0){
                        if(j == 0 && k == 0){
                            d[i,j,k] = 1;
                        }
                        else{
                            d[i,j,k] = 0;
                        }
                    }
                    else{
                        d[i,j,k] = 0;
                    }
                }
            }
        }
        for(int i=1;i<M+1;i++){
            for(int j=0;j<N;j++){
                for(int k=j;k<N+1;k++){
                    if(k != 0){
                        d[i,j,k] = (d[i,j,k] + (d[i-1,j,k] * (k-j-1) % Define.mod)) % Define.mod;
                        d[i,k-1,k] = (d[i,k-1,k] + (d[i-1,j,k] * (j+1) % Define.mod)) % Define.mod;
                    }
                    if(k != N){
                        if(k == 0){
                            d[i,j,k+1] = (d[i,j,k+1] + d[i-1,j,k]) % Define.mod;
                        }
                        else{
                            d[i,j,k+1] = (d[i,j,k+1] + (d[i-1,j,k] * (N-k) % Define.mod)) % Define.mod;
                        }
                    }
                }
            }
        }
        sb.Append(d[M,N-1,N]+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        M = int.Parse(str[1])+1;
    }    
}
public static class Define{
    public const long mod = 1000000007;
}