fn getline() -> String{ let mut __ret=String::new(); std::io::stdin().read_line(&mut __ret).ok(); return __ret; } fn mpow(x: i64, y: i64) -> i64 { match y { 0 => 1, _ => (x.pow((y % 2) as u32) * mpow(x * x % 1000000007, y / 2)) % 1000000007 } } fn main(){ let s=getline(); let a:Vec<_>=s.trim().split(' ').collect(); let (n, m): (i64, i64) = (a[0].parse().unwrap(), a[1].parse().unwrap()); let mut r = mpow(m, n); let mut zeros = m; let mut zdiv =1; (1..m).for_each(|i| { let patterns = mpow(m-i, n) % 1000000007; r = (if (i % 2) == 0 {r + patterns * (zeros * mpow(zdiv, 1000000007-2) % 1000000007) % 1000000007} else {(r + 1000000007 - patterns * (zeros * mpow(zdiv, 1000000007-2) % 1000000007) % 1000000007) % 1000000007}) % 1000000007; zeros = zeros * (m-i) % 1000000007; zdiv = zdiv * (i+1) % 1000000007; }); print!("{} ", r); }