#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

/// min{x | x * (x + 1) / 2 >= v }
fn calc(v: i64) -> i64 {
    assert! (v > 0);
    let piv = (2. * v as f64).sqrt() as i64;
    for k in max(piv - 10, 0) .. piv + 10 {
        if k * (k + 1) >= 2 * v {
            return k;
        }
    }
    panic!();
}

fn solve() {
    let n: i64 = get();
    let m: i64 = get();
    if n <= m {
        println!("{}", n);
        return;
    }
    println!("{}", m + calc(n - m));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn main() {
    let (n, m): (u64, u64) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    if n <= m {
        println!("{}", n);
        return;
    }

    let n_max = 2_000_000_000 + m;

    let mut lower_bound: u64 = m;
    let mut upper_bound: u64 = n_max;

    let check = |k| {
        (k - m) * (k - m + 1) / 2 >= n - m
    };

    while upper_bound - lower_bound != 1 {
        let middle = (lower_bound + upper_bound) / 2;
        if check(middle) {
            upper_bound = middle;
        } else {
            lower_bound = middle;
        }
    }

    let ans = upper_bound;

    println!("{}", ans);
}


use std::io;

static ALPHABET: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

fn find_number_of_ops(length_of_string: usize, s: String) -> usize {
    let mut number_of_ops = vec![];
    for i in 0..length_of_string-3 {
        let substring = &s[i..i+4];
        let mut ops = 0;
        for (index_of_letter_in_substring, letter) in substring.chars().enumerate() {
            if letter != "ACTG".chars().nth(index_of_letter_in_substring).unwrap() {
                // number of operations is not zero for this letter
                let position_of_letter_in_alphabet = ALPHABET.find(letter).unwrap();
                let position_of_target_in_alphabet = ALPHABET.find("ACTG".chars().nth(index_of_letter_in_substring).unwrap()).unwrap();
                let x: usize = (position_of_letter_in_alphabet as isize - position_of_target_in_alphabet as isize).abs() as usize;
                let y: usize = 26 - (position_of_target_in_alphabet as isize - position_of_letter_in_alphabet as isize).abs() as usize;
                ops += if x < y {x} else {y};
            }
            if index_of_letter_in_substring == 3 {
                number_of_ops.push(ops);
            }
        }
    }
    let mut minimum_ops = number_of_ops[0];
    for ops in number_of_ops.iter() {
        if ops < &minimum_ops {
            minimum_ops = *ops;
        }
    }
    minimum_ops
}

fn main() {
    let mut length_of_string = String::new();
    io::stdin().read_line(&mut length_of_string).unwrap();
    let length_of_string: usize = length_of_string.trim().parse().unwrap();
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    println!("{}", find_number_of_ops(length_of_string, s.trim().to_string()));
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 1_000_000_007;

/// Refers external ::MOD.
/// Verified by: https://beta.atcoder.jp/contests/arc099/submissions/2893648
mod mod_int {
    use ::MOD;
    use std::ops::*;
    #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt { pub x: i64 }
    impl ModInt {
        fn check_integrity(self) {
            debug_assert!(self.x >= 0);
            debug_assert!(self.x < MOD);
        }
        // x >= 0
        pub fn new(x: i64) -> Self { ModInt { x: x % MOD } }
        #[allow(dead_code)]
        pub fn mul_fast(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            ModInt { x: self.x * other.x % MOD }
        }
        #[allow(dead_code)]
        pub fn mul_slow(self, other: Self) -> Self {
            // Naive multiplication in order to avoid overflow
            self.check_integrity();
            other.check_integrity();
            let mut sum = ModInt::new(0);
            let mut cur = self;
            let mut e = other.x;
            if self.x < other.x {
                cur = other;
                e = self.x;
            }
            while e > 0 {
                if e % 2 == 1 {
                    sum = sum + cur;
                }
                cur = cur + cur;
                e /= 2;
            }
            sum
        }
        pub fn pow(self, mut e: i64) -> Self {
            self.check_integrity();
            debug_assert!(e >= 0);
            let mut sum = ModInt::new(1);
            let mut cur = ModInt::new(self.x);
            while e > 0 {
                if e % 2 != 0 {
                    sum = sum * cur;
                }
                cur = cur * cur;
                e /= 2;
            }
            sum
        }
        pub fn inv(self) -> Self { self.pow(MOD - 2) }
    }
    impl Add for ModInt {
        type Output = Self;
        fn add(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            let mut sum = self.x + other.x;
            if sum >= MOD { sum -= MOD; }
            ModInt { x: sum }
        }
    }
    impl Sub for ModInt {
        type Output = Self;
        fn sub(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            let mut sum = self.x - other.x;
            if sum < 0 { sum += MOD; }
            ModInt { x: sum }
        }
    }
    impl Mul for ModInt {
        type Output = Self;
        fn mul(self, other: Self) -> Self {
            self.mul_fast(other)
        }
    }
    impl ::std::fmt::Display for ModInt {
        fn fmt(&self, f: &mut::std::fmt::Formatter) -> ::std::fmt::Result {
            self.x.fmt(f)
        }
    }
} // mod mod_int

use mod_int::*;

fn solve() {
    let n: usize = get();
    let s: Vec<char> = get_word().chars().collect();
    let m = s.len();
    let mut rev = vec![vec![0; m + 1]; 2];
    for i in 0 .. m {
        let idx = if s[i] == '(' { 0 } else { 1 };
        let opp = if s[i] == '(' { ')' } else { '(' };
        let mut grow = s[0 .. i].to_vec();
        grow.push(opp);
        let mut aa = 0;
        for j in 0 .. i + 1 {
            if grow[j ..] == s[.. i + 1 - j] {
                aa = i + 1 - j;
                break;
            }
        }
        rev[1 - idx][i] = aa;
        rev[idx][i] = i + 1;
    }
    rev[0][m] = m;
    rev[1][m] = m;
    let mut dp = vec![vec![vec![ModInt::new(0); m + 1]; n + 1]; 2 * n + 1];
    dp[0][0][0] = ModInt::new(1);
    for i in 0 .. 2 * n {
        for j in 0 .. n + 1 {
            for k in 0 .. m + 1 {
                if j < n {
                    dp[i + 1][j + 1][rev[0][k]] =
                        dp[i + 1][j + 1][rev[0][k]] + dp[i][j][k];
                }
                if j > 0 {
                    dp[i + 1][j - 1][rev[1][k]] =
                        dp[i + 1][j - 1][rev[1][k]] + dp[i][j][k];
                }
            }
        }
    }
    println!("{}", dp[2 * n][0][m]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


// ---------- begin ModInt ----------
const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

/*
impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
*/

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        self.pow(MOD - 2)
    }
    pub fn comb(n: u32, k: u32) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        let k = std::cmp::min(k, n - k);
        let mut nu = ModInt::one();
        let mut de = ModInt::one();
        for i in 0..k {
            nu *= ModInt(n - i);
            de *= ModInt(i + 1);
        }
        nu * de.inv()
    }
}

#[allow(dead_code)]
struct Precalc {
    inv: Vec<ModInt>,
    fact: Vec<ModInt>,
    ifact: Vec<ModInt>,
}

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end ModInt ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        s: chars,
    }
    let len = s.len();
    let mut index = vec![vec![0; len + 1]; 2];
    for i in 0..len {
        if s[i] == '(' {
            index[0][i] = i + 1;
            let mut t = s.clone();
            t[i] = ')';
            for k in (1..=i).rev() {
                if s[0..k] == t[(i + 1 - k)..(i + 1)] {
                    index[1][i] = k;
                    break;
                }
            }
        } else {
            index[1][i] = i + 1;
            let mut t = s.clone();
            t[i] = '(';
            for k in (1..=i).rev() {
                if s[0..k] == t[(i + 1 - k)..(i + 1)] {
                    index[0][i] = k;
                    break;
                }
            }
        }
    }
    index[0][len] = len;
    index[1][len] = len;
    let mut dp = vec![vec![ModInt::zero(); n + 1]; len + 1];
    dp[0][0] = ModInt::one();
    for _ in 0..(2 * n) {
        let mut next = vec![vec![ModInt::zero(); n + 1]; len + 1];
        for j in 0..=len {
            for k in 0..=n {
                let v = dp[j][k];
                if k < n {
                    next[index[0][j]][k + 1] += v;
                }
                 if k > 0 {
                    next[index[1][j]][k - 1] += v;
                }
            }
        }
        dp = next;
    }
    let ans = dp[len][0].0;
    println!("{}", ans);
}

fn main() {
    run();
}


use std::io;
use std::mem::swap;
use std::str;

fn has_valid_prime_factors(n: i64) -> bool {
    let mut n = n;
    while n % 2 == 0 {
        n /= 2;
    }
    while n % 3 == 0 {
        n /= 3;
    }
    while n % 5 == 0 {
        n /= 5;
    }
    n == 1
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn factorize(n: i64) -> Vec<(i64, i64)> {
    let mut n = n;
    let mut p = 2;
    let mut ans = Vec::new();
    while p * p <= n && n > 1 {
        let mut expo = 0;
        while n % p == 0 {
            expo += 1;
            n /= p;
        }
        if expo > 0 {
            ans.push((p, expo));
        }
        p += 1;
    }
    if n > 1 {
        ans.push((n, 1));
    }
    ans
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let mut a: i64 = scan.token();
    let mut b: i64 = scan.token();
    if a > b {
        swap(&mut a, &mut b);
    }

    // a and b must be reduced each to its gcd.
    // a should become gcd(a, b) only dividing it by 2, 3 or 5.
    // b should become gcd(a, b) only dividing it by 2, 3 or 5.
    // In other words, a / gcd(a, b) and b / gcd(a, b) must only have 2, 3 or 5 as prime factors.
    let g = gcd(a, b);
    if a == b || (has_valid_prime_factors(a / g) && has_valid_prime_factors(b / g)) {
        let factors_without_gcd = factorize((a / g) * (b / g));
        let ans = factors_without_gcd.iter().fold(0i64, |acc, val| acc + val.1);
        writeln!(out, "{}", ans).ok();
    } else {
        writeln!(out, "-1").ok();
    }
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }

    pub fn tokens<T: str::FromStr>(&mut self) -> Vec<T> {
        assert!(self.buffer.is_empty());
        let mut input = String::new();
        self.reader.read_line(&mut input).expect("Failed read");
        input
            .split_whitespace()
            .map(|x| x.parse().ok().expect("Failed parse"))
            .collect()
    }
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn get_order(x: usize, y: usize) -> usize {
    if x == 0 {
        return 0;
    }
    let mut x = x;
    let mut count = 0usize;
    while x % y == 0 {
        x /= y;
        count += 1;
    }
    count
}

fn _main() {
    let mut scan = Scan::new();
    let mut a: usize = scan.next();
    let mut b: usize = scan.next();
    let mut result = 0usize;
    let possible: Vec<usize> = vec![2, 3, 5];
    for i in possible {
        let ia = get_order(a, i);
        let ib = get_order(b, i);
        let diff = ia.max(ib) - ia.min(ib);
        result += diff;

        if ia > ib {
            a /= i.pow(diff as u32);
        } else if ia < ib {
            b /= i.pow(diff as u32);
        }
    }
    if a != b {
        println!("-1");
    } else {
        println!("{}", result);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


#[allow(unused_imports)]
use std::cmp::{max,min};
#[allow(unused_imports)]
use std::collections::{HashMap,HashSet,VecDeque};

#[allow(unused_macros)]
macro_rules! readln {
    () => {{
        use std::io;

        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

#[allow(unused_macros)]
macro_rules! readvec {
    ( $t:ty ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        let mut result = Vec::new();
        for elem in input {
            result.push(elem.parse::<$t>().unwrap());
        }
        result
    }}
}

fn main() {
    let (mut a, mut b) = readln!(i32,i32);
    let mut res = 0;
    while a>0 && b>0 && !(a==1 && b==1){
        res += 1;
        if a >= b {
            a = max(0,a-2);
            b = min(100,b+1);
        } else {
            a = min(100,a+1);
            b = max(0,b-2);
        }
    }
    println!("{}",res);
}


//spnauti-rust
#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
use std::io::*;
use std::str::*;
use std::fmt::Debug;
struct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).unwrap();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let mut a = input.i();
    let mut b = input.i();
    let mut sol = 0;
    while a > 0 && b > 0 && a + b > 2 {
        if a < b {
            a += 1;
            b -= 2;
        } else {
            a -= 2;
            b += 1;
        }
        sol += 1;
    }
    println!("{}", sol);
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn minval(a1: usize, a2: usize, depth: usize, table: &mut [[usize; 256]; 256]) -> usize {
    if a1 == 0 || a2 == 0 {
        return depth;
    }
    if table[a1][a2] != 0 {
        return table[a1][a2];
    }
    let mut result = 0usize;
    if a2 >= 2 {
        let val = {
            let a1 = a1 + 1;
            let a2 = a2 - 2;
            minval(a1.max(a2), a1.min(a2), depth + 1, table)
        };
        result = result.max(val);
    }
    if a1 >= 2 {
        let val = {
            let a1 = a1 - 2;
            let a2 = a2 + 1;
            minval(a1.max(a2), a1.min(a2), depth + 1, table)
        };
        result = result.max(val);
    }
    table[a1][a2] = result;
    result
}

fn _main() {
    let mut table = [[0; 256]; 256];
    let mut scan = Scan::new();
    let a1: usize = scan.next();
    let a2: usize = scan.next();
    let result = minval(a1.max(a2), a1.min(a2), 0, &mut table);
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn dfs(a: &[u64], k: usize, sup: bool, used: u64, b: &mut Vec<u64>) {
    if k == a.len() {
        b.push(used);
        return;
    }
    let y = if !sup {
        a[k]
    } else {
        6
    };
    for i in 0..=y {
        if used >> i & 1 == 0 {
            dfs(a, k + 1, sup || i < a[k], used | (1 << i), b);
        }
    }
}

fn run() {
    input! {
        n: u64,
        m: u64,
    }
    let mut a = vec![];
    let mut x = m - 1;
    if x == 0 {
        a.push(0);
    } else {
        while x > 0 {
            a.push(x % 7);
            x /= 7;
        }
    }
    a.reverse();
    let mut b = vec![];
    dfs(&a, 0, false, 0, &mut b);
    let sa = a;
    let mut a = vec![];
    let mut x = n - 1;
    if x == 0 {
        a.push(x);
    } else {
        while x > 0 {
            a.push(x % 7);
            x /= 7;
        }
    }
    if a.len() + sa.len() > 7 {
        println!("0");
        return;
    }
    a.reverse();
    let mut c = vec![];
    dfs(&a, 0, false, 0, &mut c);
    let mut ans = 0;
    for b in b.iter() {
        for c in c.iter() {
            if *b & *c == 0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


use std::collections::LinkedList;
use std::iter::FromIterator;

macro_rules! read_line {
    ($v:ident) => {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).unwrap();
        let $v = temp;
    };
    (var, $t:ty, $($v:ident), *) => {
        read_line!(input_line);
        let mut iter = parse_token!($t, input_line);
        $(
            let $v = iter.next().unwrap();
        )*
    };
    (vec, $t:ty, $v:ident) => {
        read_line!(input_line);
        let iter = parse_token!($t, input_line);
        let $v: Vec<$t> = iter.collect();
    };
    ($($v:ident; $t:ty), *) => {
        read_line!(input_line);
        let mut iter = input_line.split_whitespace();
        $(
            let $v: $t = iter.next().unwrap().parse().unwrap();
        )*
    };
}

macro_rules! parse_token {
    ($t:ty, $e:expr) => {
        $e.split_whitespace().map(|x| x.parse::<$t>().unwrap());
    };
}

fn trivial_coincide(a_barrier: &LinkedList<i32>, b_barrier: &LinkedList<i32>) -> bool {
    let iter = a_barrier.iter().zip(b_barrier.iter());
    let mut difference = None;
    for (a, b) in iter {
        match difference {
            Some(diff) => {
                if (*a - *b) != diff {
                    return false;
                }
            },
            None => {
                difference = Some(*a - *b);
            }
        }
    }
    return true;
}

fn main() {
    read_line!(barriers;i32,track_length;i32);
    read_line!(vec,i32,a_barrier);
    read_line!(vec,i32,b_barrier);
    let a_barrier = LinkedList::from_iter(a_barrier.into_iter());
    let mut b_barrier = LinkedList::from_iter(b_barrier.into_iter());
    for _ in 0..barriers {
        let extend_front = b_barrier.pop_front().unwrap() + track_length;
        b_barrier.push_back(extend_front);
        if trivial_coincide(&a_barrier, &b_barrier) {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


fn main() {
    let (_, l) = {
        let r = getvec::<i32>();
        (r[0] as usize, r[1])
    };
    let a = getvec::<i32>();
    let b = getvec::<i32>();
    let am = calc(&a, l);
    // for x in am.clone() {
    //     println!("{}", x);
    // }
    let bm = calc(&b, l);
    println!("{}",
             match ok(&am, &bm) {
                 true => "YES",
                 false => "NO",
             });
}
fn ok(a: &Vec<i32>, b: &Vec<i32>) -> bool {
    let n = a.len();
    for i in 0..n {
        let mut r = true;
        for j in 0..n {
            let j_ = (j + i) % n;
            if a[j] != b[j_] {
                r = false;
                break;
            }
        }
        if r {
            return true;
        }
    }
    false
}
fn calc(seq: &Vec<i32>, l: i32) -> Vec<i32> {
    let mut res = Vec::new();
    let n = seq.len();
    for i in 0..n - 1 {
        res.push(seq[i + 1] - seq[i]);
    }
    res.push(l - seq[n - 1] + seq[0]);
    res
}
#[allow(dead_code)]
fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}

#[allow(dead_code)]
fn getnum<T: std::str::FromStr>() -> T {
    let res = next_line();
    res.trim().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn getvec<T: std::str::FromStr>() -> Vec<T> {
    let res = next_line();
    res.split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}


#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let l: usize = sc.cin();

    let mut a = vec![false; l];
    {
        a[0] = true;
        let base: usize = sc.cin();
        for i in 1..n {
            let x: usize = sc.cin();
            a[(x - base + l) % l] = true;
        }
    }
    trace!(a);

    let mut ys = vec![0; n];
    for i in 0..n {
        let y = sc.cin();
        ys[i] = y;
    }

    for base in 0..l {
        let mut ok = true;
        for i in 0..n {
            if !a[(ys[i] + base + l) % l] {
                ok = false;
                break;
            }
        }
        if ok {
            println!("YES");
            return;
        }
    }

    println!("NO");
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


// Practice Codeforces
// author: Leonardone @ NEETSDKASU

// 解説読後

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }

    let n = get!();
    let m = get!(usize);

    if n < -2000 {
        let ans = brute_force(n, m as i64);
        println!("{}", ans);
    }

    let mut xs = vec![0; m];

    for i in 0..m {
        let mut c = n / m as i64;
        if i as i64 <= n % m as i64 {
            c += 1;
        }
        xs[i * i % m] += c;
    }
    xs[0] -= 1;
    // println!("{:?}", xs);
    let mut ans = 0;
    let c = n / m as i64;
    for i in 0..xs.len() {
        for j in 0..xs.len() {
            let k = (i+j) % m;
            if k == 0 {
                ans += xs[i] * xs[j];
            }
        }
    }

    println!("{}", ans);
}

fn brute_force(n: i64, m: i64) -> i64 {
    let mut ret = 0;
    for i in 1..=n {
        for j in 1..=n {
            let k = i * i + j * j;
            if k % m == 0 {
                ret += 1;
            }
        }
    }
    ret
}


use std::io::stdin;
use std::cmp::min;

pub fn process(n: i32, m: i32) -> u64 {
  let mut res: u64 = 0;
  for i in 1..=min(m, n) {
    for j in 1..=min(m, n) {
      if (i * i + j * j) % m != 0 { continue }
      let k = ((n - i) / m) as u64;
      let l = ((n - j) / m) as u64;
      res += ((k + 1) * (l + 1));
    }
  }
  res
}

fn main() {
  let mut s = String::new();
  stdin().read_line(&mut s).unwrap();
  let mut input = s.split_whitespace();
  let n = input.next().unwrap().parse::<i32>().unwrap();
  let m = input.next().unwrap().parse::<i32>().unwrap();

  println!("{}", process(n, m));
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn test1() {
    assert_eq!(process(3, 3), 1);
  }

  #[test]
  fn test2() {
    assert_eq!(process(6, 5), 13);
  }

  #[test]
  fn test3() {
    assert_eq!(process(1000_000_000, 1), 1000_000_000_000_000_000);
  }
  #[test]
  fn test4() {
    assert_eq!(process(15, 1_000), 0);
  }
}


// Practice Codeforces
// author: Leonardone @ NEETSDKASU

// 解説読後

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }

    let n = get!();
    let m = get!(usize);

    if n < -2000 {
        let ans = brute_force(n, m as i64);
        println!("{}", ans);
    }

    let mut xs = vec![0; m];

    for i in 0..m {
        let mut c = n / m as i64;
        if i as i64 <= n % m as i64 {
            c += 1;
        }
        xs[i] += c;
    }
    xs[0] -= 1;
    // println!("{:?}", xs);
    let mut ans = 0;
    let c = n / m as i64;
    for i in 0..xs.len() {
        for j in 0..xs.len() {
            let k = (i*i+j*j) % m;
            if k == 0 {
                ans += xs[i] * xs[j];
            }
        }
    }

    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    fn _gcd(a: i64, b: i64) -> i64 {
        if a == 0 { b } else { _gcd(b % a, a) }
    }
    let a = a.abs();
    let b = b.abs();
    if a < b { _gcd(a, b) } else { _gcd(b, a) }
}

fn brute_force(n: i64, m: i64) -> i64 {
    let mut ret = 0;
    for i in 1..=n {
        for j in 1..=n {
            let k = i * i + j * j;
            if k % m == 0 {
                ret += 1;
            }
        }
    }
    ret
}


#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_labels)]

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

const MAX:usize = 30;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

struct Graph {
    e: Vec<Vec<usize>>,
    v: Vec<usize>,
    u: Vec<usize>,
    f: Vec<bool>,
    c: i64,
    vc: Vec<i64>,
}

impl Graph {
    fn new(n:usize) -> Self {
        Graph {
            e: vec![vec![];n],
            v: vec![],
            u: vec![n;n],
            f: vec![false;n],
            c: 0,
            vc: vec![0;n],
        }
    }

    fn dfs(&mut self, crt: usize) {
        if self.f[crt] { return; }
        self.c += 1;
        self.f[crt] = true;
        self.v.push(crt);
        self.vc[crt] = self.c;
        self.u[crt] = self.v.len()-1;
        for i in 0..self.e[crt].len() {
            self.dfs(self.e[crt][i]);
        }
        //debug!(crt, self.c, self.vc[crt]);
        self.vc[crt] = self.c - self.vc[crt];
    }
}

fn main() {
    //let t:usize = read();

    //'outer: for _ in 0..t {
        let n:usize = read();
        let k:i64 = read();
        let a:Vec<i64> = (0..n).map(|_| read()).collect();

        let mut idx = 0;
        for i in 0..n {
            if a[i] > k { break; }
            idx = i+1;
        }
        let mut idx2 = n;
        for i in (0..n).rev() {
            if a[i] > k { break; }
            idx2 = i;
        }
        if idx == n {
            println!("{}", n);
        } else {
            println!("{}", idx+(n-idx2));
        }
    //}
}

/*

*/


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

    fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next::<T>()).collect()
    }
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let k: usize = scan.next();
    let arr: Vec<usize> = scan.next_n(n);
    let mut result = 0usize;
    for &item in arr.iter() {
        if item <= k {
            result += 1;
        } else {
            break;
        }
    }
    let initial = result;
    for &item in arr.iter().skip(initial).rev() {
        if item <= k {
            result += 1;
        } else {
            break;
        }
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


fn read_ints() -> Vec<i32> {
    let mut ln = String::new();
    std::io::stdin().read_line(&mut ln).expect("");
    ln.split_whitespace().filter_map(|w| w.parse().ok()).collect()
}

fn main() {
    let (n, k): (usize, i32);
    if let [_n, _k] = read_ints()[..] { n = _n as usize; k = _k; } else { panic!("> <"); }
    let a = read_ints();
    assert_eq!(n, a.len());

    let mut ans = 0;
    for &el in a.iter() {
        if el <= k { ans += 1; } else { break; }
    }
    for &el in a.iter().rev() {
        if el <= k { ans += 1; } else { break; }
    }

    if ans == n * 2 { ans = n; }
    println!("{}", ans);
}


use std::io;

fn main() {
    let mut input_text = String::new();
    io::stdin().read_line(&mut input_text).expect("fail");
    let input_text = input_text.trim();
    let mut tuples = input_text.split_whitespace();
    let n = tuples.next().unwrap().parse::<u32>().expect("parse error");
    let k = tuples.next().unwrap().parse::<u32>().expect("parse error");

    let mut input_text = String::new();
    io::stdin().read_line(&mut input_text).expect("fail");
    let list = input_text.split_whitespace();
    let numbers: Vec<&str> = list.collect();

    let mut max = std::u32::MIN;
    let mut min = std::u32::MAX;
    for i in 0..n {
        let x = numbers[i as usize].parse::<u32>().expect("parse error");
        if x > k {
            max = std::cmp::max(i, max);
            min = std::cmp::min(i, min);
        }
    }

    if min > max {
        println!("{}", n);
    } else if min == max {
        println!("{}", n-1);
    } else {
        println!("{}", n - (max - min + 1));
    }
}


use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: i32 = sc.next();
    let k: i32 = sc.next();
    let v: Vec<i32> = sc.next_vec(n as _);

    let mut l = 0;
    let mut r = n - 1;
    let mut ans = 0;

    while l <= r {
        if v[l as usize] <= k {
            l += 1;
            ans += 1;
        } else if v[r as usize] <= k {
            r -= 1;
            ans += 1;
        } else {
            break;
        }
    }

    println!("{}", ans);
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


use std:: io;

fn read_ints() -> Vec<u8> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.split_whitespace().filter_map(|ss| ss.parse().ok()).collect()
}

fn main() {
    let n: u8;
    let k: u8;
    if let [_n, _k] = read_ints()[..] { n = _n; k = _k; } else { panic!("x"); }

    let a: Vec<u8> = read_ints();

    let mut ans: u8 = 0;
    let mut flag: usize = n as usize - 1;
    for (i, aa) in a.iter().enumerate() {
        if aa <= &k {
            ans += 1;
        } else {
            flag = i;
            break;
        }
    }
    flag = n as usize - 1 - flag;
    for (i, aa) in a.iter().rev().enumerate() {
        if i < flag && aa <= &k {
            ans += 1;
        } else {
            break;
        }
    }

    println!("{}", ans);

    return;
}


use std:: io;

fn read_ints() -> Vec<u8> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.split_whitespace().filter_map(|ss| ss.parse().ok()).collect()
}

fn main() {
    let n: u8;
    let k: u8;
    if let [_n, _k] = read_ints()[..] { n = _n; k = _k; } else { panic!("x"); }

    let a: Vec<u8> = read_ints();

    let mut ans: u8 = 0;
    //let mut flag: usize = n as usize - 1;
    //for (i, aa) in a.iter().enumerate() {
        //if aa <= &k {
            //ans += 1;
        //} else {
            //flag = i;
            //break;
        //}
    //}
    //flag = n as usize - 1 - flag;
    //for (i, aa) in a.iter().rev().enumerate() {
        //if i < flag && aa <= &k {
            //ans += 1;
        //} else {
            //break;
        //}
    //}

    for aa in a.iter() {
        if aa <= &k { ans += 1; }
        else { break; }
    }
    for aa in a.iter().rev() {
        if aa <= &k { ans += 1; }
        else { break; }
    }

    if ans == n * 2 { ans = n }

    println!("{}", ans);

    return;
}


use std::io;
use std::collections::VecDeque;

fn main() {
    let mut count = 0;
    let num = read();
    let mut text = VecDeque::new();
    let number = read();
    for a in number.into_iter() {
        text.push_back(a);
    }
    loop {
        let a = text.pop_front();
        if a <= Some(*&num[1]) {
            if a != None {
                count += 1;
                continue;
            }
        }
        break;
    }
    loop {
        let a = text.pop_back();
        if a <= Some(*&num[1]) {
            if a != None {
                count += 1;
                continue;
            }
        }
        break;
    }
    println!("{}", count);
}

fn read() -> Vec<i32> {
    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    a.trim().to_string();
    let mut num = Vec::new();
    for a in a.split_whitespace() {
        num.push(a.parse::<i32>().unwrap());
    }
    num
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::*;
#[allow(unused_imports)] use std::collections::*;

#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

#[allow(dead_code)]
fn build_counting_hashmap<K: Eq + std::hash::Hash, T>(i: T) -> HashMap<K,usize>
    where T: Iterator<Item = K> {
    let mut m = HashMap::new();
    for k in i {
        let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };
        m.insert(k, n);
    }
    m
}

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let s = "aeiou13579";
    let sol = input.sl().chars().filter(|&c| s.chars().any(|a| a == c)).count();
    println!("{}", sol);
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn is_vowel(ch: char) -> bool {
    return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

fn _main() {
    let mut scan = Scan::new();
    let mut result = 0usize;
    for ch in scan.next::<String>().chars() {
        if is_vowel(ch) || ch.to_digit(10).unwrap_or(2) % 2 == 1 {
            result += 1;
        }
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


#[allow(unused_imports)]
use std::cmp::{max,min};
#[allow(unused_imports)]
use std::collections::{HashMap,HashSet,VecDeque};

#[allow(unused_macros)]
macro_rules! readln {
    () => {{
        use std::io;

        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

#[allow(unused_macros)]
macro_rules! readvec {
    ( $t:ty ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        let mut result = Vec::new();
        for elem in input {
            result.push(elem.parse::<$t>().unwrap());
        }
        result
    }}
}

fn is_vowel(z: char)->bool {
  let s = "aeoiu";
  return s.chars().any(|x|x==z);
}

fn is_odd(z: char)->bool {
  let s = "13579";
  return s.chars().any(|x|x==z);
}

fn main() {
let s = readln!();
println!("{}",s.chars().filter(|&x| is_vowel(x) || is_odd(x)).count());
}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let line = read_vector::<usize>();
    let (n, k) = (line[0], line[1] - 1);
    let min_n = min(k, n - 1 - k);
    println!("{}", 3 * n + min_n);
}

#[allow(dead_code)]
fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::with_capacity(100);
    stdin().read_line(&mut buf).unwrap();
    return buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::io::prelude::*;
    let stdin = stdin();
    let mut reader = BufReader::with_capacity(100 * 1024, stdin);
    let mut line = String::with_capacity(100);
    let mut matrix: Vec<Vec<T>> = Vec::new();

    while reader.read_line(&mut line).unwrap() > 0 {
        matrix.push(
            line.trim()
                .split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect(),
        );
        line.clear();
    }

    return matrix;
}

#[allow(dead_code)]
fn read_chars() -> Vec<char> {
    let stdin = stdin();
    let mut buf = String::new();
    let _bytes = stdin.read_line(&mut buf).unwrap();
    return buf.trim().chars().collect();
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i32,
        k: i32,
    }
    let ans = min((n - k) + n - 1, (k - 1) + n - 1);
    puts!("{}\n", ans + 2 * n + 1);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
// input macro
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
    }
    println!("{}", 2 * n + min(k - 1, n - k) * 2 + max(k - 1, n - k) + 1);
}


//spnauti-rusT
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::*;
#[allow(unused_imports)] use std::iter::*;
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($i:ident . $e:tt : $t:ty; $($a:ident),*) => {
        $( let $a: $t = $i.$e(); )*
    };
    ($i:ident . $e:tt; $($a:ident),*) => {
        $( let $a = $i.$e(); )*
    };
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a> }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let n = input.u();
    let sol = (1..).flat_map(|a| a.to_string().into_bytes()).nth(n - 1);
    println!("{}", sol.unwrap() as char);
}


#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::{*};
use std::io::{BufWriter, stdin, stdout, Write};
const BITS: usize = 19;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scanner = Scanner::default();
    let (a, b, c): (f64, f64, f64) = (scanner.next(), scanner.next(), scanner.next());
    let tot = (a*b*c).sqrt();
    println!["{}", 4.0*(tot/a + tot/b + tot/c)];
}


fn main() {
    let areas: Vec<f64> = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();

    let a = (areas[0] * areas[1] / areas[2]).sqrt();
    let b = (areas[0] * areas[2] / areas[1]).sqrt();
    let c = (areas[2] * areas[1] / areas[0]).sqrt();
    let res = 4 * (a+b+c) as u32;

    println!("{}", res);

}

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer.trim().to_owned()
}

fn get_input_usize() -> usize {
    get_input().parse().unwrap()
}


macro_rules! scan {
    ( $string:expr, $sep:expr, $( $x:ty ),+ ) => {{
        let mut iter = $string.split($sep);
        ($(iter.next().and_then(|word| word.parse::<$x>().ok()).unwrap(),)*)
    }}
}

use std::io;

fn dist(l: &mut i32, r: &mut i32, a: &i32) {
    for _ in 0..*a {
        if l <= r {
            *l += 1;
        } else {
            *r += 1;
        }
    }
}

fn cnt(l: &i32, r: &i32) -> i32 {
    std::cmp::min(*l, *r) * 2
}

fn solve(mut l: i32, mut r: i32, a: i32) -> i32 {
    dist(&mut l, &mut r, &a);
    cnt(&l, &r)
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();

    let (l, r, a) = scan!(buf, char::is_whitespace, i32, i32, i32);

    println!("{}", solve(l, r, a));
}

#[cfg(test)]
mod test{
    use super::*;

    #[test]
    fn test_dist() { let (mut l, mut r, a) = (2, 3, 5);

        dist(&mut l, &mut r, &a);
        assert_eq!(l, 5);
        assert_eq!(r, 5);

        let (mut l, mut r, a) = (1, 5, 5);

        dist(&mut l, &mut r, &a);
        assert_eq!(l, 6);
        assert_eq!(r, 5);
    }

    #[test]
    fn test_cnt() {
        assert_eq!(cnt(&2, &3), 4);
        assert_eq!(cnt(&3, &4), 6);
        assert_eq!(cnt(&1, &0), 0);
        assert_eq!(cnt(&0, &0), 0);
    }

    #[test]
    fn acpt() {
        assert_eq!(solve(1, 4, 2), 6);
        assert_eq!(solve(5, 5, 5), 14);
        assert_eq!(solve(0, 2, 0), 0);
    }
}


use std::io;
use std::cmp;

pub fn main() {
    let mut input_string = String::new();
    io::stdin().read_line(&mut input_string)
        .expect("uh oh");
    let input_vector: Vec<u64> = input_string
        .split_whitespace()
        .map(|x| x.parse::<u64>()
             .expect("uh oh"))
        .collect();
    let max = cmp::max(input_vector[0], input_vector[1]);
    let min = cmp::min(input_vector[0], input_vector[1]);
    if min + input_vector[2] > max {
        let extra = input_vector[2] - (max - min);
        println!("{}", (max + extra / 2) * 2);
    } else {
        println!("{}", (min + input_vector[2]) * 2);
    }
}


#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter {
        s: String::new(),
        }
    }

    fn print<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn main() {
    let mut printer = ContestPrinter::new();

    let (L, R, A) = readl!(i32, i32, i32);
    let mut l = L;
    let mut r = R;
    if l > r {
        r += A;
    } else {
        l += A;
    }
    while (l - r).abs() > 1 {
        if l > r {
            if l == L { break; }
            l -= 1;
            r += 1;
        } else {
            if r == R { break; }
            r -= 1;
            l += 1;
        }
    }
    printer.println(2 * min(l, r));
}


// Basics

#![allow(unused_imports)]

use std::mem;
use std::io;
use std::string;
use std::cmp::*;
use std::collections::*;

fn load() -> Vec<i64> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let vec: Vec<&str> = line.split(" ").collect();
    let mut data: Vec<i64> = Vec::new();
    for i in vec {
        let el: i64 = i.trim().parse().unwrap();
        data.push(el);
    }
    data
}

fn main() {
    let w = load();
    let (a, b) = (w[0], w[1]);
    if b - a >= 10 {
        println!("0");
    } else {
        let mut end = 1;
        for i in (a + 1)..(b + 1) {
            end *= i % 10;
        }
        println!("{}", (end % 10));
    }
}

//
//mod strings;
//
//fn main() {
//    strings_sample();
//}


fn read_line() -> String {
    let stdin = std::io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    String::from(line.trim())
}

macro_rules! scan_line {
    ($($ty: ty),*) => {{
        let line = read_line();
        let mut tok = line.split_whitespace();
        ($(tok.next().unwrap().parse::<$ty>().unwrap()),*)
    }}
}

fn main() {
    let (a, b) = scan_line!(u64, u64);
    let mut acc = 1;
    for i in (a + 1)..(b + 1) {
        acc = (acc * i % 10) % 10;
        if acc == 0 {
            break;
        }
    }
    println!("{}", acc);
}


#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn main() {
    let (a, b): (u64, u64) = util::get2();

    let mut f = 1;

    for x in a + 1..b + 1 {
        f = (f * (x % 10)) % 10;
        if f == 0 {
            break;
        }
    }

    println!("{}", f);
}


#![allow(dead_code, unused_imports)]

use std::fmt::Debug;
use std::str::FromStr;

fn read_stdin() -> String {
    let mut s = String::new();
    std::io::stdin()
        .read_line(&mut s)
        .expect("cannot read stdin");
    s.trim().to_string()
}

fn read<T>() -> T
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_stdin().parse::<T>().unwrap()
}

fn read_usize() -> usize {
    read::<usize>()
}

fn read_2<A, B>() -> (A, B)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    (a, b)
}

fn read_3<A, B, C>() -> (A, B, C)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    (a, b, c)
}

fn read_4<A, B, C, D>() -> (A, B, C, D)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
    D: FromStr,
    <D as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    let d = s.next().unwrap().parse::<D>().unwrap();
    (a, b, c, d)
}

fn read_multiple<T: FromStr>() -> Vec<T>
where
    <T as FromStr>::Err: Debug,
{
    read_stdin()
        .split_whitespace()
        .map(|x| x.parse::<T>().expect("cannot parse stdin"))
        .collect()
}

/// NOTE: sort iter beforehand if required
fn count<T>(iter: &mut impl Iterator<Item = T>) -> Vec<(T, usize)>
where
    T: std::cmp::Ord,
{
    let iter = iter.collect::<Vec<_>>();
    //iter.sort();
    let (mut v, o, c) =
        iter.into_iter()
            .fold((Vec::new(), None, 0), |(mut v, last, count), item| {
                if let Some(o) = last {
                    if item == o {
                        (v, Some(o), count + 1)
                    } else {
                        v.push((o, count));
                        (v, Some(item), 1)
                    }
                } else {
                    (v, Some(item), 1)
                }
            });
    if let Some(i) = o {
        v.push((i, c));
    }
    v
}

fn partial_sum<T>(v: impl Iterator<Item = T>) -> impl Iterator<Item = T>
where
    T: Default + std::ops::Add<Output = T> + Copy,
{
    v.scan(T::default(), |state, x| {
        *state = *state + x;
        Some(*state)
    })
}

fn max_subarray(v: impl Iterator<Item = i64>) -> (i64, (usize, usize)) {
    //assert!(v.len() > 0);
    let mut best_sum = 0;
    let (mut best_start, mut best_end) = (0, 0);
    let mut current_sum = 0;
    let mut current_start = 0;
    for (end, val) in v.enumerate() {
        if current_sum <= 0 {
            current_start = end;
            current_sum = val;
        } else {
            current_sum += val;
        }
        if current_sum > best_sum {
            best_sum = current_sum;
            best_start = current_start;
            best_end = end + 1;
        }
    }
    (best_sum, (best_start, best_end))
}

fn gcd(mut a: u64, mut b: u64) -> u64 {
    while a != 0 {
        let old_m = a;
        a = b % a;
        b = old_m;
    }
    b
}

/// returns gcd, and pair (x, y), such that x * a + b * y == gcd
fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
    if a == 0 {
        (b, 0, 1)
    } else {
        let (g, x, y) = egcd(b % a, a);
        (g, y - (b / a) * x, x)
    }
}

fn factorize(mut n: u64) -> Vec<u64> {
    if n <= 3 {
        return vec![n];
    }
    let mut v = Vec::new();
    while n % 2 == 0 {
        n /= 2;
        v.push(2);
    }
    while n % 3 == 0 {
        n /= 3;
        v.push(3);
    }
    let mut f = 6;
    while (f - 1) * (f - 1) <= n {
        while n % (f - 1) == 0 {
            n /= f - 1;
            v.push(f - 1);
        }
        while n % (f + 1) == 0 {
            n /= f + 1;
            v.push(f + 1);
        }
        f += 6;
    }
    if n > 1 {
        v.push(n);
    }
    v
}

fn compact_factors(n: u64) -> Vec<(u64, usize)> {
    count(&mut factorize(n).into_iter())
}

fn all_factors(n: u64) -> Vec<u64> {
    if n == 0 {
        return vec![0];
    } else if n == 1 {
        return vec![1];
    }
    let factors = compact_factors(n);
    let mut v = vec![1];
    for (fac, num) in factors {
        let ori = v.clone();
        for i in 1..num + 1 {
            v.append(
                &mut ori
                    .clone()
                    .into_iter()
                    .map(|f| f * fac.pow(i as u32))
                    .collect::<Vec<_>>(),
            )
        }
    }
    v.sort();
    v
}

fn abs_diff<T>(a: T, b: T) -> T
where
    T: PartialOrd + std::ops::Sub<Output = T>,
{
    if a > b {
        a - b
    } else {
        b - a
    }
}

struct Permutations<T> {
    inner: Vec<T>,
    state: Vec<usize>,
    i: usize,
    start: bool,
}

impl<T> Permutations<T> {
    fn new(inner: Vec<T>) -> Self {
        Self {
            state: vec![0; inner.len()],
            i: 0,
            start: true,
            inner,
        }
    }
}

/*impl<T, X> From<X> for Permutations<T>
where
    X: IntoIterator<Item = T>,
{
    fn from(f: X) -> Self {
        Self::new(f.into_iter().collect::<Vec<T>>())
    }
}*/

impl<T> Iterator for Permutations<T>
where
    T: Clone,
{
    type Item = Vec<T>;
    fn next(&mut self) -> Option<Self::Item> {
        if self.start {
            self.start = false;
            return Some(self.inner.clone());
        }
        while self.i < self.inner.len() {
            if self.state[self.i] < self.i {
                if self.i % 2 == 0 {
                    self.inner.swap(0, self.i)
                } else {
                    self.inner.swap(self.state[self.i], self.i)
                }
                self.state[self.i] += 1;
                self.i = 0;
                return Some(self.inner.clone());
            } else {
                self.state[self.i] = 0;
                self.i += 1;
            }
        }
        None
    }
}

use std::cmp::{max, min, Ord, Ordering};
use std::collections::{BinaryHeap, VecDeque};
use std::mem::swap;

#[derive(Clone)]
struct Graph {
    nodes: usize,
    edges: Vec<Vec<(usize, u64)>>,
}

impl Graph {
    fn new(n: usize) -> Self {
        Self {
            nodes: n,
            edges: vec![Vec::new(); n + 1],
        }
    }

    fn add_edge(&mut self, x: usize, y: usize, cost: u64) {
        self.edges[x].push((y, cost));
        self.edges[y].push((x, cost));
    }

    fn dijkstra(&mut self, start: usize, end: usize) -> u64 {
        let mut dist = vec![None; self.nodes + 1];
        let mut prev = vec![None; self.nodes + 1];
        dist[start] = Some(0);
        let mut queue = (1..=self.nodes).collect::<Vec<_>>();
        queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));
        queue.reverse();
        while let Some(next_node) = queue.pop() {
            if next_node == end {
                return dist[next_node].unwrap();
            }
            for (neighbour, cost) in self.edges[next_node].iter() {
                let alt = dist[next_node].unwrap() + cost;
                if dist[*neighbour].is_none() {
                    dist[*neighbour] = Some(alt);
                    prev[*neighbour] = Some(next_node);
                } else {
                    if alt < dist[*neighbour].unwrap() {
                        dist[*neighbour] = Some(alt);
                        prev[*neighbour] = Some(next_node);
                    }
                }
            }
            //println!("{:?} {:?}", dist, prev);
            queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));
            queue.reverse();
        }
        0
    }

    fn set_cost(&mut self, x: usize, y: usize, cost: u64) {
        for i in 0..self.edges[x].len() {
            if self.edges[x][i].0 == y {
                self.edges[x][i].1 = cost
            }
        }
        for i in 0..self.edges[y].len() {
            if self.edges[y][i].0 == x {
                self.edges[y][i].1 = cost
            }
        }
    }
}

const MODULO: u64 = 1_000_000_007;

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
struct BigPrimeRing {
    inner: u64,
}

impl<T> From<T> for BigPrimeRing
where
    T: Into<u64>,
{
    fn from(n: T) -> Self {
        Self {
            inner: n.into() % MODULO,
        }
    }
}

impl<T> std::ops::Add<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn add(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner + rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::AddAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn add_assign(&mut self, rhs: T) {
        self.inner += rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl<T> std::ops::Sub<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn sub(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner + MODULO - rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::SubAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn sub_assign(&mut self, rhs: T) {
        self.inner += MODULO;
        self.inner -= rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl<T> std::ops::Mul<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn mul(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner * rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::MulAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn mul_assign(&mut self, rhs: T) {
        self.inner *= rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl BigPrimeRing {
    fn inverse(self) -> Self {
        if self.inner == 0 {
            return self;
        }
        let (_g, mut x, _y) = egcd(self.inner as i64, MODULO as i64);
        if x < 0 {
            x += MODULO as i64;
        }
        Self { inner: x as u64 }
    }
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (a, b) = read_2::<u64, u64>();
    let mut res = 1;
    'lop: for i in (a + 1)..=b {
        res *= i;
        res %= 10;
        if res == 0 {
            break 'lop;
        }
    }
    println!("{}", res);
    Ok(())
}


use std::io::{self, Write};

fn inv(mut a: i64, modulo: i64) -> i64 {
    let mut b: i64 = modulo - 2;
    let mut ans: i64 = 1;
    while b > 0 {
        if b & 1 == 1 {
            ans = (ans * a) % modulo;
        }
        a = (a * a) % modulo;
        b >>= 1;
    }
    ans
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut sc = cf_scanner::Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    let (n, modulo): (usize, i64) = (sc.next(), sc.next());

    let mut pow2: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| pow2[i] = (2 * pow2[i-1]) % modulo);

    let mut fact: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| fact[i] = (i as i64 * fact[i-1]) % modulo);

    let i_fact: Vec<i64> = (0..=n).map(|i| inv(fact[i], modulo)).collect();

    let mut choose: Vec<Vec<i64>> = vec![vec![0; n + 1]; n + 1];
    for i in 0..=n {
        for j in 0..=i {
            choose[i][j] = ((fact[i] * i_fact[j]) % modulo * i_fact[i - j]) % modulo;
        }
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; n + 5]; n + 5];
    dp[0][0] = 1;
    for i in 1..=n {
        dp[i][i] = pow2[i-1];
        for j in 1..=i {
            for k in 1..j {
                if i < k + 1 {
                    break;
                }
                dp[i][j] += ((pow2[k-1] * choose[j][k]) % modulo * dp[i - k - 1][j - k]) % modulo;
                dp[i][j] %= modulo;
            }
        }
    }

    let ans: i64 = (1..=n).fold(0 as i64, |x, y| (x + dp[n][y]) % modulo);

    writeln!(out, "{}", ans).unwrap();
}

#[allow(dead_code)]
mod cf_scanner {
    use std::io;
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub struct Scanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> Scanner<R> {
        pub fn new(reader: R) -> Scanner<R> {
            Scanner {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buf_iter.next() {
                    return token.parse().ok().expect("Failed parse");
                }
                self.buf_str.clear();
                self.reader
                    .read_until(b'\n', &mut self.buf_str)
                    .expect("Failed read");
                self.buf_iter = unsafe {
                    let slice = std::str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
}


use std::io::{self, Write};

fn inv(mut a: i64, modulo: i64) -> i64 {
    let mut b: i64 = modulo - 2;
    let mut ans: i64 = 1;
    while b > 0 {
        if b & 1 == 1 {
            ans = (ans * a) % modulo;
        }
        a = (a * a) % modulo;
        b >>= 1;
    }
    ans
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut sc = cf_scanner::Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    let (n, modulo): (usize, i64) = (sc.next(), sc.next());

    let mut pow2: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| pow2[i] = (2 * pow2[i-1]) % modulo);

    let mut fact: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| fact[i] = (i as i64 * fact[i-1]) % modulo);

    let i_fact: Vec<i64> = (0..=n).map(|i| inv(fact[i], modulo)).collect();

    let choose: Vec<Vec<i64>> = (0..=n).map(|i| {
        (0..=i).map(|j| ((fact[i] * i_fact[j]) % modulo * i_fact[i - j]) % modulo).collect()
    }).collect();

    let mut dp: Vec<Vec<i64>> = vec![vec![0; n + 5]; n + 5];
    dp[0][0] = 1;
    for i in 1..=n {
        dp[i][i] = pow2[i-1];
        for j in 1..=i {
            for k in 1..j {
                if i < k + 1 {
                    break;
                }
                dp[i][j] += ((pow2[k-1] * choose[j][k]) % modulo * dp[i - k - 1][j - k]) % modulo;
                dp[i][j] %= modulo;
            }
        }
    }

    let ans: i64 = (1..=n).fold(0 as i64, |x, y| (x + dp[n][y]) % modulo);

    writeln!(out, "{}", ans).unwrap();
}

#[allow(dead_code)]
mod cf_scanner {
    use std::io;
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub struct Scanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> Scanner<R> {
        pub fn new(reader: R) -> Scanner<R> {
            Scanner {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buf_iter.next() {
                    return token.parse().ok().expect("Failed parse");
                }
                self.buf_str.clear();
                self.reader
                    .read_until(b'\n', &mut self.buf_str)
                    .expect("Failed read");
                self.buf_iter = unsafe {
                    let slice = std::str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
}


#![allow(unused_imports, unused_macros)]

use kyoproio::*;
use std::{
    collections::*,
    io::{self, prelude::*},
    iter, mem,
};

fn run<I: Input, O: Write>(mut kin: I, mut out: O) {
    let t: usize = 1; // kin.parse();
    for _ in 0..t {
        case(&mut kin, &mut out);
    }
}
fn case<I: Input, O: Write>(mut kin: I, mut out: O) {
    let (n, m): (usize, u32) = kin.parse();
    set_var_mod(m);
    let mut dp = vec![vec![mint(0); n + 1]; n + 1]; // [count][pos]
    let mut miss = vec![mint(0); n + 1];
    miss[0] = mint(1);
    let mut any = vec![vec![mint(0); n + 1]; n + 1];
    for i in 1..=n {
        let mut dp_new = vec![vec![mint(0); n + 1]; n + 1];
        let mut any_new = vec![vec![mint(0); n + 1]; n + 1];
        for c in 0..i {
            let mut sum = mint(0);
            for j in 0..c {
                sum += dp[c][j] + any[c][j];
                dp_new[c + 1][j + 1] += sum;
            }
            let miss_new = sum;
            let mut sum = mint(0);
            for j in (0..c).rev() {
                sum += any[c][j];
                any_new[c + 1][j] += sum;
            }
            for j in 0..=c {
                any_new[c + 1][j] += miss[c];
            }
            miss[c] = miss_new;
        }
        dp = dp_new;
        any = any_new;
        // d!(dp, any, miss);
    }
    let s1: Mint = dp.iter().flatten().copied().sum();
    let s2: Mint = any.iter().flatten().copied().sum();
    let ans = s1 + s2;
    wln!(out, "{}", ans);
}
use std::{cmp, fmt, marker::PhantomData, ops, sync::atomic};
pub type Mint = ModInt<VarMod>;
pub fn mint(x: u32) -> Mint {
    ModInt::new(x)
}
pub trait Modulo {
    fn modulo() -> u32;
}
macro_rules! modulo_impl {
    ($($Type:ident $val:tt)*) => {
        $(pub struct $Type;
        impl Modulo for $Type {
            fn modulo() -> u32 {
                $val
            }
        })*
    };
}
modulo_impl!(Mod998244353 998244353 Mod1000000007 1000000007);
pub struct VarMod;
static VAR_MOD: atomic::AtomicU32 = atomic::AtomicU32::new(0);
pub fn set_var_mod(m: u32) {
    VAR_MOD.store(m, atomic::Ordering::Relaxed);
}
impl Modulo for VarMod {
    fn modulo() -> u32 {
        VAR_MOD.load(atomic::Ordering::Relaxed)
    }
}
#[repr(transparent)]
pub struct ModInt<M>(u32, PhantomData<*const M>);
impl<M: Modulo> ModInt<M> {
    pub fn new(x: u32) -> Self {
        debug_assert!(x < M::modulo());
        Self(x, PhantomData)
    }
    pub fn normalize(self) -> Self {
        if self.0 < M::modulo() {
            self
        } else {
            Self::new(self.0 % M::modulo())
        }
    }
    pub fn get(self) -> u32 {
        self.0
    }
    pub fn inv(self) -> Self {
        assert_ne!(self, Self::new(0));
        self.pow(M::modulo() - 2)
    }
    pub fn half(self) -> Self {
        Self::new(self.0 / 2 + self.0 % 2 * ((M::modulo() + 1) / 2))
    }
    pub fn modulo() -> u32 {
        M::modulo()
    }
}
impl<M: Modulo> ops::Neg for ModInt<M> {
    type Output = Self;
    fn neg(self) -> Self {
        Self::new(if self.0 == 0 { 0 } else { M::modulo() - self.0 })
    }
}
impl<M: Modulo> ops::Add for ModInt<M> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        let s = self.0 + rhs.0;
        Self::new(if s < M::modulo() { s } else { s - M::modulo() })
    }
}
impl<M: Modulo> ops::Sub for ModInt<M> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        Self::new(if self.0 >= rhs.0 {
            self.0 - rhs.0
        } else {
            M::modulo() + self.0 - rhs.0
        })
    }
}
impl<M: Modulo> ops::Mul for ModInt<M> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        Self::new((self.0 as u64 * rhs.0 as u64 % M::modulo() as u64) as u32)
    }
}
impl<M: Modulo> ops::Div for ModInt<M> {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        self * rhs.inv()
    }
}
macro_rules! op_impl {
    ($($Op:ident $op:ident $OpAssign:ident $op_assign:ident)*) => {
        $(impl<M: Modulo> ops::$Op<&Self> for ModInt<M> {
            type Output = Self;
            fn $op(self, rhs: &Self) -> Self {
                self.$op(*rhs)
            }
        }
        impl<M: Modulo> ops::$Op<ModInt<M>> for &ModInt<M> {
            type Output = ModInt<M>;
            fn $op(self, rhs: ModInt<M>) -> ModInt<M> {
                (*self).$op(rhs)
            }
        }
        impl<M: Modulo> ops::$Op<&ModInt<M>> for &ModInt<M> {
            type Output = ModInt<M>;
            fn $op(self, rhs: &ModInt<M>) -> ModInt<M> {
                (*self).$op(*rhs)
            }
        }
        impl<M: Modulo> ops::$OpAssign for ModInt<M> {
            fn $op_assign(&mut self, rhs: Self) {
                *self = ops::$Op::$op(*self, rhs);
            }
        }
        impl<M: Modulo> ops::$OpAssign<&ModInt<M>> for ModInt<M> {
            fn $op_assign(&mut self, rhs: &ModInt<M>) {
                self.$op_assign(*rhs);
            }
        })*
    };
}
op_impl! {
    Add add AddAssign add_assign
    Sub sub SubAssign sub_assign
    Mul mul MulAssign mul_assign
    Div div DivAssign div_assign
}
impl<M: Modulo> std::iter::Sum for ModInt<M> {
    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(ModInt::new(0), |x, y| x + y)
    }
}
impl<M: Modulo> std::iter::Product for ModInt<M> {
    fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(ModInt::new(1), |x, y| x * y)
    }
}
pub trait Pow<T> {
    fn pow(self, n: T) -> Self;
}
impl<M: Modulo> Pow<u32> for ModInt<M> {
    fn pow(mut self, mut n: u32) -> Self {
        let mut y = Self::new(1);
        while n > 0 {
            if n % 2 == 1 {
                y *= self;
            }
            self *= self;
            n /= 2;
        }
        y
    }
}
macro_rules! mod_int_pow_impl {
    ($($T:ident)*) => {
        $(impl<M: Modulo> Pow<$T> for ModInt<M> {
            fn pow(self, n: $T) -> Self {
                self.pow(n.rem_euclid(M::modulo() as $T - 1) as u32)
            }
        })*
    };
}
mod_int_pow_impl!(isize i32 i64 usize u64);
macro_rules! mod_int_from_impl {
    ($($T:ident)*) => {
        $(impl<M: Modulo> From<$T> for ModInt<M> {
            #[allow(unused_comparisons)]
            fn from(x: $T) -> Self {
                if M::modulo() <= $T::max_value() as u32 {
                    Self::new(x.rem_euclid(M::modulo() as $T) as u32)
                } else if x < 0 {
                    Self::new((M::modulo() as i32 + x as i32) as u32)
                } else {
                    Self::new(x as u32)
                }
            }
        })*
    }
}
mod_int_from_impl!(isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128);
impl<M> Copy for ModInt<M> {}
impl<M> Clone for ModInt<M> {
    fn clone(&self) -> Self {
        *self
    }
}
impl<M: Modulo> Default for ModInt<M> {
    fn default() -> Self {
        Self::new(0)
    }
}
impl<M> cmp::PartialEq for ModInt<M> {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}
impl<M> cmp::Eq for ModInt<M> {}
impl<M> cmp::PartialOrd for ModInt<M> {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        self.0.partial_cmp(&other.0)
    }
}
impl<M> cmp::Ord for ModInt<M> {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        self.0.cmp(&other.0)
    }
}
impl<M> std::hash::Hash for ModInt<M> {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.0.hash(state);
    }
}
impl<M> fmt::Display for ModInt<M> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}
impl<M> fmt::Debug for ModInt<M> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

// -----------------------------------------------------------------------------
fn main() -> io::Result<()> {
    std::thread::Builder::new()
        .stack_size(1 << 26)
        .spawn(|| {
            run(
                Scanner::new(io::stdin().lock()),
                io::BufWriter::new(io::stdout().lock()),
            )
        })?
        .join()
        .unwrap();
    Ok(())
}

#[macro_export]
macro_rules! w {
    ($($arg:tt)*) => { write!($($arg)*).unwrap(); }
}
#[macro_export]
macro_rules! wln {
    ($dst:expr $(, $($arg:tt)*)?) => {{
        writeln!($dst $(, $($arg)*)?).unwrap();
        #[cfg(debug_assertions)]
        $dst.flush().unwrap();
    }}
}
#[macro_export]
macro_rules! w_iter {
    ($dst:expr, $fmt:expr, $iter:expr, $delim:expr) => {{
        let mut first = true;
        for elem in $iter {
            if first {
                w!($dst, $fmt, elem);
                first = false;
            } else {
                w!($dst, concat!($delim, $fmt), elem);
            }
        }
    }};
    ($dst:expr, $fmt:expr, $iter:expr) => {
        w_iter!($dst, $fmt, $iter, " ")
    };
}
#[macro_export]
macro_rules! w_iter_ln {
    ($dst:expr, $($t:tt)*) => {{
        w_iter!($dst, $($t)*);
        wln!($dst);
    }}
}
#[macro_export]
macro_rules! e {
    ($($t:tt)*) => {
        #[cfg(debug_assertions)]
        eprint!($($t)*)
    }
}
#[macro_export]
macro_rules! eln {
    ($($t:tt)*) => {
        #[cfg(debug_assertions)]
        eprintln!($($t)*)
    }
}
#[macro_export]
macro_rules! __tstr {
    ($h:expr $(, $t:expr)+) => { concat!(__tstr!($($t),+), ", ", __tstr!(@)) };
    ($h:expr) => { concat!(__tstr!(), " ",  __tstr!(@)) };
    () => { "\x1B[94m[{}:{}]\x1B[0m" };
    (@) => { "\x1B[1;92m{}\x1B[0m = {:?}" }
}
#[macro_export]
macro_rules! d {
    ($($a:expr),*) => { eln!(__tstr!($($a),*), file!(), line!(), $(stringify!($a), $a),*) };
}

pub mod kyoproio {
    use std::{
        fmt::Display,
        io::{self, prelude::*},
        iter::FromIterator,
        marker::PhantomData,
        mem::{self, MaybeUninit},
        str,
    };

    pub trait Input {
        fn bytes(&mut self) -> &[u8];
        fn str(&mut self) -> &str {
            str::from_utf8(self.bytes()).unwrap()
        }
        fn parse<T: Parse>(&mut self) -> T {
            T::parse(self)
        }
        fn parse_iter<T: Parse>(&mut self) -> ParseIter<T, Self> {
            ParseIter(self, PhantomData)
        }
        fn collect<T: Parse, B: FromIterator<T>>(&mut self, n: usize) -> B {
            self.parse_iter().take(n).collect()
        }
        fn map<T: Parse, U, F: FnMut(T) -> U, B: FromIterator<U>>(&mut self, n: usize, f: F) -> B {
            self.parse_iter().take(n).map(f).collect()
        }
    }
    impl<I: Input> Input for &mut I {
        fn bytes(&mut self) -> &[u8] {
            (**self).bytes()
        }
    }
    pub struct Scanner<R> {
        src: R,
        buf: Vec<u8>,
        pos: usize,
        len: usize,
    }
    impl<R: Read> Scanner<R> {
        pub fn new(src: R) -> Self {
            Self {
                src,
                buf: vec![0; 1 << 16],
                pos: 0,
                len: 0,
            }
        }
        fn read(&mut self) -> usize {
            if self.pos > 0 {
                self.buf.copy_within(self.pos..self.len, 0);
                self.len -= self.pos;
                self.pos = 0;
            } else if self.len >= self.buf.len() {
                self.buf.resize(2 * self.buf.len(), 0);
            }
            let n = self.src.read(&mut self.buf[self.len..]).unwrap();
            self.len += n;
            assert!(self.len <= self.buf.len());
            n
        }
    }
    impl<R: Read> Input for Scanner<R> {
        fn bytes(&mut self) -> &[u8] {
            loop {
                while let Some(d) = unsafe { self.buf.get_unchecked(self.pos..self.len) }
                    .iter()
                    .position(u8::is_ascii_whitespace)
                {
                    let p = self.pos;
                    self.pos += d + 1;
                    if d > 0 {
                        return unsafe { self.buf.get_unchecked(p..p + d) };
                    }
                }
                if self.read() == 0 {
                    let p = self.pos;
                    self.pos = self.len;
                    return unsafe { self.buf.get_unchecked(p..self.len) };
                }
            }
        }
    }
    pub struct ParseIter<'a, T, I: ?Sized>(&'a mut I, PhantomData<*const T>);
    impl<'a, T: Parse, I: Input + ?Sized> Iterator for ParseIter<'a, T, I> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            Some(self.0.parse())
        }
        fn size_hint(&self) -> (usize, Option<usize>) {
            (!0, None)
        }
    }
    pub trait Parse: Sized {
        fn parse<I: Input + ?Sized>(src: &mut I) -> Self;
    }
    macro_rules! from_bytes {
        ($($T:ty)*) => {$(
            impl Parse for $T {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.bytes().into()
                }
            }
        )*}
    }
    from_bytes!(Vec<u8> Box<[u8]>);
    macro_rules! from_str {
        ($($T:ty)*) => {$(
            impl Parse for $T {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.str().parse::<$T>().unwrap()
                }
            }
        )*}
    }
    from_str!(String char bool f32 f64);
    macro_rules! int {
        ($($I:ty: $U:ty)*) => {$(
            impl Parse for $I {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    let f = |s: &[u8]| s.iter().fold(0, |x, b| 10 * x + (b & 0xf) as $I);
                    let s = src.bytes();
                    if let Some((&b'-', t)) = s.split_first() { -f(t) } else { f(s) }
                }
            }
            impl Parse for $U {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.bytes().iter().fold(0, |x, b| 10 * x + (b & 0xf) as $U)
                }
            }
        )*}
    }
    int!(isize:usize i8:u8 i16:u16 i32:u32 i64:u64 i128:u128);
    macro_rules! tuple {
        ($H:ident $($T:ident)*) => {
            impl<$H: Parse, $($T: Parse),*> Parse for ($H, $($T),*) {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    ($H::parse(src), $($T::parse(src)),*)
                }
            }
            tuple!($($T)*);
        };
        () => {}
    }
    tuple!(A B C D E F G);
    macro_rules! array {
        ($($N:literal)*) => {$(
            impl<T: Parse> Parse for [T; $N] {
                fn parse<I: Input + ?Sized>(src: &mut I) -> Self {
                    unsafe {
                        let mut arr: [MaybeUninit<T>; $N] = MaybeUninit::uninit().assume_init();
                        for elem in &mut arr {
                            *elem = MaybeUninit::new(src.parse());
                        }
                        mem::transmute_copy(&arr)
                    }
                }
            }
        )*}
    }
    array!(1 2 3 4 5 6 7 8);
}