use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let arr : Vec<i64> = s.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let (mut n, k) = (arr[0], arr[1]);
    for _i in 0..k {
        if n % 10 == 0 {
            n /= 10;
        } else {
            n -= 1;
        }
    }
    println!("{}", n);
}


use std::io::stdin;

pub fn main() {
    let mut nums: Vec<i32> = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.trim()
            .split_whitespace()
            .map(str::parse)
            .map(Result::unwrap)
            .collect()
    };
    nums.sort();
    println!("{}", nums[2] - nums[1] + nums[1] - nums[0]);
}


use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let split_input : Vec<&str> = input.as_str().split(' ').collect();
    let a : i32 = split_input[0].trim().parse().expect("en");
    let b : i32 = split_input[1].trim().parse().expect("en");
    let c : i32 = split_input[2].trim().parse().expect("en");
    let mut minimum: i32 = 300;
    for i in 1..100 {
        if (a - i).abs() + (b - i).abs() + (c - i).abs() < minimum {
            minimum = (a - i).abs() + (b - i).abs() + (c - i).abs();
        }
    }
    println!("{}", minimum);
}


fn input_split() -> Vec<u16> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|elem| elem.parse().unwrap())
        .collect()
}

fn determine_b(v: &[u16]) -> Option<u16> {
    let sum: u16 = v.iter().sum();
    if sum % 5 == 0 && sum != 0 {
        Some(sum / 5)
    } else {
        None
    }
}

fn print(res: Option<u16>) {
    match res {
        Some(val) => print!("{}", val),
        None => print!("-1"),
    }
}

fn main() {
    print(determine_b(&input_split()))
}


//spna-rust
#[allow(unused_imports)]
use std::io::{self,Read};

#[derive(Debug)]
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T : Read>(mut reader : T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader { it : s
            .split_ascii_whitespace()
            .map(String::from).collect::<Vec<_>>()
            .into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let mut a = input.ab();
    a.sort();
    a.dedup();
    if a.len() % 2 == 0 {
        println!("CHAT WITH HER!");
    } else {
        println!("IGNORE HIM!");
    }
}


// author: zkmrgirish
// date: 10 Apr, Friday

#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashSet;
use std::io::{stdin, stdout, BufWriter, Write};

#[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 scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

    let username: String = scan.next();
    let mut set = HashSet::new();

    for x in username.chars() {
        set.insert(x);
    }

    writeln!(
        out,
        "{}",
        if set.len() % 2 == 0 {
            "CHAT WITH HER!"
        } else {
            "IGNORE HIM!"
        }
    )
    .ok();
}


use std::io::{self, prelude::*, Write};
use std::str;
use std::string::String;
use std::vec::Vec;

use std::cmp;

#[allow(unused_must_use)]
fn run<B: BufRead, W: Write>(mut reader: Scanner<B>, mut writer: W) {
    let total_number_of_trips: i32 = reader.next();
    let number_of_trips_with_special_ticket: i32 = reader.next();
    let one_trip_price: i32 = reader.next();
    let special_ticket_price: i32 = reader.next();

    let number_of_special_tickets_bought: i32 = total_number_of_trips / number_of_trips_with_special_ticket;
    let mut total_cost: i32 = number_of_special_tickets_bought * special_ticket_price;
    let remaining_trips_needed: i32 = total_number_of_trips % number_of_trips_with_special_ticket;
    if remaining_trips_needed > 0 {
        total_cost += cmp::min(remaining_trips_needed * one_trip_price, special_ticket_price);
    }

    total_cost = cmp::min(total_cost, total_number_of_trips * one_trip_price);

    writeln!(writer, "{}", total_cost);
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();

    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    run(reader, writer);
    io::stdout().flush().unwrap();
}

pub struct Scanner<B> {
    reader: B,
    buffer_string: Vec<u8>,
    buffer_iterator: str::SplitWhitespace<'static>,
}

impl <B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        return Self {
            reader,
            buffer_string: Vec::new(),
            buffer_iterator: "".split_whitespace()
        };
    }

    pub fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            //if buffer already exists, just use existing buffer
            if let Some(token) = self.buffer_iterator.next() {
                return token.parse().ok().expect("Fail to parse token");
            }

            //get new line
            self.buffer_string.clear();
            self.reader.read_until(b'\n', &mut self.buffer_string).expect("Failed to read");

            //split by white space
            self.buffer_iterator = unsafe {
                let slice = str::from_utf8_unchecked(&self.buffer_string);
                std::mem::transmute(slice.split_whitespace())
            };
        }
    }

    pub fn next_line(&mut self) -> String {
        //reset buffer
        self.buffer_iterator = "".split_whitespace();
        self.buffer_string.clear();

        let mut input: String = String::new();
        self.reader.read_line(&mut input).expect("Failed to read line");
        return input.trim().to_string();
    }
}


use std::io::*;

fn reads<T: std::str::FromStr>(i: &mut StdinLock) -> Vec<T> {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let params: Vec<u32> = reads(sin);

    let n = params[0];
    let m = params[1];
    let a = params[2];
    let b = params[3];

    let ans = if a * m < b {
        n * a
    } else {
        let base = n / m;
        let remain = n % m;
        (base * b) + std::cmp::min(remain * a, b)
    };

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


fn main() {
    let (n, m, z) = {
        let r = getvec::<i64>();
        (r[0], r[1], r[2])
    };
    let gc = gcd(n, m);
    let lca = n * m / gc;
    println!("{}", z / lca);
}
fn gcd(a: i64, b: i64) -> i64 {
    match b {
        0i64 => a,
        _ => gcd(b, a % b),
    }
}

#[allow(dead_code)]
fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).ok().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 gcd(a: i64, b: i64) -> i64 { if b == 0 { a } else { gcd(b, a % b) } }

fn main() {
    let mut sc = Scanner::new();
    let m: i64 = sc.cin();
    let n: i64 = sc.cin();
    let z: i64 = sc.cin();

    let a = z / (m * n / gcd(m, n));
        println!("{}", a);
}

#[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
    }
}


use std::io;

pub fn get_years(weights: Vec<u32>) -> u32 {
    let mut years = 0;
    let mut limak = weights[0];
    let mut bob = weights[1];

    while limak <= bob {
        years += 1;
        limak *= 3;
        bob *= 2;
    }

    years
}

pub fn solution() -> io::Result<()> {
    let mut weights = String::new();

    io::stdin().read_line(&mut weights)?;
    let numbers: Vec<u32> = weights
        .trim()
        .split(" ")
        .map(|num| num.parse::<u32>().expect("Couldn't parse number"))
        .collect();

    println!("{}", get_years(numbers));
    Ok(())
}

fn main() {
    solution();
}


use std::io;

fn read() -> String{
    let mut input=String::new();
    io::stdin().read_line(&mut input).expect("unable to read");
    input.trim().to_string()
}
fn main() {
    let inp=read();
    let list: Vec<_>=inp.split_whitespace().collect();
    let mut b1=list[0].parse::<i32>().expect("Failed to parse");
    let mut b2=list[1].parse::<i32>().expect("Failed to parse");
    let mut years=0;
    while b2>=b1{
        b1*=3;
        b2*=2;
        years+=1
    }println!("{}",years);
}


// http://codeforces.com/problemset/problem/1/A

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

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

    let input: Vec<_> = buffer.split_whitespace().collect();
    let n = input[0].parse().unwrap();
    let m = input[1].parse().unwrap();
    let a = input[2].parse().unwrap();

    println!("{}", pave(n, m, a));
}

fn pave(n: u64, m: u64, a: u64) -> u64 {
    //cover n
    let cover_n = if n % a == 0 { n / a } else { (n / a) + 1 };
    let cover_m = if m % a == 0 { m / a } else { (m / a) + 1 };

    cover_m * cover_n
}


use std::io;
fn main(){
    let mut s:String=String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut a:Vec<i64>=Vec::new();
    let mut c:usize=0;
    let mut n:usize=0;
    while c<=s.len()-1{
        n=c;
        if s.chars().nth(c).unwrap()!=' '{
            while s.chars().nth(n).unwrap()!=' ' && n<s.len()-1{
                n+=1;
            }
            a.push(s[c..n+1].trim().to_string().parse().unwrap());
            c=n;
        }
        c+=1;
    }
    if a[2]==1{println!("{}",a[0]*a[1]);return}
    let c:i64=if a[0]%a[2]>0{a[0]/a[2]+1}else{a[0]/a[2]};
    let n:i64=if a[1]%a[2]>0{a[1]/a[2]+1}else{a[1]/a[2]};
    println!("{}",c*n);
}


// https://codeforces.com/problemset/problem/520/A
use std::io;
use std::collections::HashSet;

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

    let mut line = String::new();

    io::stdin()
        .read_line(&mut line)
        .unwrap();

    let mut line: String = line
        .trim()
        .to_string();

    line.make_ascii_lowercase();

    let mut letters = HashSet::new();

    for ch in line.chars() {
        letters.insert(ch);
    }

    let alphabet = "abcdefghijklmnopqrstuvwxyz";

    let mut flag = true;

    for ch in alphabet.chars() {
        match letters.get(&ch) {
            Some(_) => continue,
            None => {
                flag = false;
                break;
            },
        }
    }

    if flag {
        println!("YES");
    } else  {
        println!("NO");
    }
}


use std::collections::HashSet;
use std::io::*;

fn read<T: std::str::FromStr>(i: &mut StdinLock) -> T {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let _n: u32 = read(sin);
    let input: String = read(sin);

    let mut set = HashSet::new();

    for c in input.to_lowercase().as_str().chars() {
        set.insert(c);
    }

    let ans = if set.len() == 26 { "YES" } else { "NO" };

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


use std::collections::BTreeMap;

fn main() {
    let (n,x) : (usize, u128) = input_t();

    if n == x.to_string().len() { println!("0"); return; }
    if x.to_string().chars().all(|c| c=='1' || c=='0') { println!("-1"); return; }
    let mut memo = BTreeMap::new();
    println!("{}", f(0,x,n,&mut memo));
    // eprintln!("{:?}", memo);
}

fn f(c:usize, x:u128,n:usize,memo:&mut BTreeMap<u128,usize>) -> usize {
    if let Some(&res) = memo.get(&x) { return res; }
    let mut t = x;
    let mut cnt = 0;
    while t!=0 { t/=10;cnt+=1;}
    if cnt >= n { return c; }

    // eprintln!("{}", x);

    let mut res = std::usize::MAX >> 4;
    for i in 2..10 {
        if !x.to_string().chars().collect::<Vec<_>>().contains(&((i+b'0') as char)) { continue }
        res = res.min(f(c, x*i as u128, n,memo) + 1);
    }

    memo.insert(x,res);
    res
}

#[allow(dead_code)] fn input<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } #[allow(dead_code)] fn input_t<T: std::str::FromStr, U: std::str::FromStr>() -> (T, U) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t3<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr>() -> (T1, T2, T3) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t4<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr, T4: std::str::FromStr>() -> (T1, T2, T3, T4) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t5<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr, T4: std::str::FromStr, T5: std::str::FromStr>() -> (T1, T2, T3, T4, T5) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap(), s[4].parse().ok().unwrap()) } #[allow(dead_code)] fn input_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect() }


#![allow(unused_imports)]

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

fn main() {
    let n: usize = read();
    let x: u64 = read();
    let target = 10_u64.pow(n as u32 - 1);
    let mut seen = HashSet::new();
    let mut heap = BinaryHeap::new();
    heap.push((len(x), x));
    while let Some((score, x)) = heap.pop() {
        if !seen.insert(x) {
            continue;
        }
        if x >= target {
            println!("{}", n as i32 - score);
            return;
        }
        let has = {
            let mut arr = [false; 10];
            let mut x = x;
            while x > 0 {
                arr[(x % 10) as usize] = true;
                x /= 10;
            }
            arr
        };
        for d in 2..=9 {
            if has[d] {
                let next = x * d as u64;
                heap.push((score - 1 + len(next) - len(x), next));
            }
        }
    }
    println!("-1");
}

fn len(mut x: u64) -> i32 {
    let mut ans = 0;
    while x > 0 {
        x /= 10;
        ans += 1;
    }
    ans
}

pub fn read<T: str::FromStr>() -> T {
    struct Tokens {
        buf: Vec<u8>,
        iter: str::SplitWhitespace<'static>,
    }
    static mut TOKENS: Option<Tokens> = None;

    let tokens = unsafe {
        TOKENS.get_or_insert_with(|| Tokens {
            buf: Vec::new(),
            iter: "".split_whitespace(),
        })
    };
    loop {
        if let Some(token) = tokens.iter.next() {
            return token.parse().ok().unwrap();
        }
        tokens.buf.clear();
        stdin().lock().read_until(b'\n', &mut tokens.buf).unwrap();
        tokens.iter = unsafe {
            let s = str::from_utf8_unchecked(&tokens.buf);
            transmute(s.split_whitespace())
        };
    }
}


pub mod solution {

use crate::io::input::Input;
use crate::io::output::output;
use crate::{out, out_line};
use std::cmp::min;
use crate::math::modular::factorial::Factorial;
use crate::math::modular::primitive::ModularType;

type Mod = ModularType<1000000007>;

fn solve(input: &mut Input, _test_case: usize) {
    let (n, k) = input.read();
    let mut ans = Mod::from(0);
    let factorials = Factorial::new(n);
    for i in 0..=min(k, n) {
        ans += factorials.combinations(n, i);
    }
    out_line!(ans);
}

pub(crate) fn run(mut input: Input) -> bool {
    solve(&mut input, 1);
    output().flush();
    input.skip_whitespace();
    !input.peek().is_some()
}

}
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::str::FromStr;

pub struct Input<'s> {
    input: &'s mut dyn Read,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

impl<'s> Input<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(input: &'s mut dyn Read) -> Self {
        Self {
            input,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {
        Self {
            input,
            buf: vec![0; buf_size],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            Some(res)
        } else {
            None
        }
    }

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            Some(self.buf[self.at])
        } else {
            None
        }
    }

    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !char::from(b).is_whitespace() {
                return;
            }
            self.get();
        }
    }

    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if char::from(c).is_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() {
            None
        } else {
            Some(res)
        }
    }

    //noinspection RsSelfConvention
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }

    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }

    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0usize..size {
            res.push(self.read());
        }
        res
    }

    pub fn read_line(&mut self) -> String {
        let mut res = String::new();
        while let Some(c) = self.get() {
            if c == b'\n' {
                break;
            }
            if c == b'\r' {
                if self.peek() == Some(b'\n') {
                    self.get();
                }
                break;
            }
            res.push(c.into());
        }
        res
    }

    #[allow(clippy::should_implement_trait)]
    pub fn into_iter<T: Readable>(self) -> InputIterator<'s, T> {
        InputIterator {
            input: self,
            phantom: Default::default(),
        }
    }

    fn read_integer<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let res = self.read_string();
        res.parse::<T>().unwrap()
    }

    fn read_string(&mut self) -> String {
        match self.next_token() {
            None => {
                panic!("Input exhausted");
            }
            Some(res) => unsafe { String::from_utf8_unchecked(res) },
        }
    }

    fn read_char(&mut self) -> char {
        self.skip_whitespace();
        self.get().unwrap().into()
    }

    fn read_float(&mut self) -> f64 {
        self.read_string().parse().unwrap()
    }

    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }
}

pub trait Readable {
    fn read(input: &mut Input) -> Self;
}

impl Readable for String {
    fn read(input: &mut Input) -> Self {
        input.read_string()
    }
}

impl Readable for char {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}

impl Readable for f64 {
    fn read(input: &mut Input) -> Self {
        input.read_float()
    }
}

impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.read_vec(size)
    }
}

pub struct InputIterator<'s, T: Readable> {
    input: Input<'s>,
    phantom: PhantomData<T>,
}

impl<'s, T: Readable> Iterator for InputIterator<'s, T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.input.skip_whitespace();
        self.input.peek().map(|_| self.input.read())
    }
}

macro_rules! read_integer {
    ($t:ident) => {
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.read_integer()
            }
        }
    };
}

read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);

macro_rules! tuple_readable {
    ( $( $name:ident )+ ) => {
        impl<$($name: Readable), +> Readable for ($($name,)+) {
            fn read(input: &mut Input) -> Self {
                ($($name::read(input),)+)
            }
        }
    }
}

tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}
}
pub mod output {
use std::io::Write;

pub struct Output {
    output: Box<dyn Write>,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
}

impl Output {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: false,
        }
    }

    pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: true,
        }
    }

    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.at = 0;
            self.output.flush().expect("Couldn't flush output");
        }
    }

    pub fn print<T: Writable>(&mut self, s: &T) {
        s.write(self);
    }

    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }

    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }

    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        for i in arg {
            i.write(self);
            self.put(b'\n');
        }
    }

    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }

    pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }
}

impl Write for Output {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        if self.auto_flush {
            self.flush();
        }
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}

pub trait Writable {
    fn write(&self, output: &mut Output);
}

impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}

impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter_ref(self.iter());
    }
}

impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self[..].write(output);
    }
}

macro_rules! write_to_string {
    ($t:ident) => {
        impl Writable for $t {
            fn write(&self, output: &mut Output) {
                self.to_string().write(output);
            }
        }
    };
}

write_to_string!(u8);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);

impl<T: Writable, U: Writable> Writable for (T, U) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
    }
}

impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
        output.put(b' ');
        self.2.write(output);
    }
}

pub static mut OUTPUT: Option<Output> = None;

pub fn output() -> &'static mut Output {
    unsafe {
        match &mut OUTPUT {
            None => {
                panic!("Panic");
            }
            Some(output) => output,
        }
    }
}

#[macro_export]
macro_rules! out {
    ($first: expr $(,$args:expr )*) => {
        output().print(&$first);
        $(output().put(b' ');
        output().print(&$args);
        )*
    }
}

#[macro_export]
macro_rules! out_line {
    ($first: expr $(, $args:expr )* ) => {
        out!($first $(,$args)*);
        output().put(b'\n');
    };
    () => {
        output().put(b'\n');
    };
}
}
}
pub mod math {
pub mod modular {
pub mod factorial {
use crate::math::modular::inverse::compute_inverse_up_to;
use crate::math::modular::primitive::Modular;

pub struct Factorial<Mod> {
    fact: Vec<Mod>,
    inverse_fact: Vec<Mod>,
}

impl<Mod> Factorial<Mod>
where
    Mod: Modular,
{
    pub fn new(n: usize) -> Self {
        let mut fact = vec![0.into(); n + 1];
        let mut inverse_fact = vec![0.into(); n + 1];
        let inv = compute_inverse_up_to(n);
        fact[0] = 1.into();
        inverse_fact[0] = 1.into();
        for i in 1..=n {
            fact[i] = fact[i - 1] * i.into();
            inverse_fact[i] = inverse_fact[i - 1] * inv[i];
        }
        Self { fact, inverse_fact }
    }

    pub fn combinations(&self, n: usize, k: usize) -> Mod {
        if k > n {
            0.into()
        } else {
            self.fact[n] * self.inverse_fact[n - k] * self.inverse_fact[k]
        }
    }
}
}
pub mod inverse {
use crate::math::modular::primitive::Modular;

pub fn compute_inverse_up_to<Mod>(n: usize) -> Vec<Mod>
where
    Mod: Modular,
{
    let mut inv: Vec<Mod> = vec![0.into(); n + 1];
    inv[1] = 1.into();
    for i in 2..=n {
        inv[i] = inv[Mod::MODULO as usize % i] * (Mod::MODULO as usize / i).into();
        inv[i] = -inv[i];
    }
    inv
}
}
pub mod primitive {
use crate::io::output::{Output, Writable};
use std::ops::{Add, AddAssign, Mul, Neg};

#[derive(Copy, Clone)]
pub struct ModularType<const M: u32>(u32);

pub trait Modular:
    Add<Output = Self>
    + AddAssign
    + Mul<Output = Self>
    + Neg<Output = Self>
    + From<usize>
    + From<i32>
    + From<u32>
    + Writable
    + Copy
{
    const MODULO: u32;
    fn value(&self) -> u32;
    fn usize(&self) -> usize {
        self.value() as usize
    }
}

impl<const M: u32> Modular for ModularType<M> {
    const MODULO: u32 = M;

    fn value(&self) -> u32 {
        self.0
    }
}

impl<const M: u32> Add for ModularType<M> {
    type Output = ModularType<M>;

    fn add(self, rhs: Self) -> Self::Output {
        let result = self.0 + rhs.0;
        ModularType(if result >= M { result - M } else { result })
    }
}

impl<const M: u32> AddAssign for ModularType<M> {
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        if self.0 >= M {
            self.0 -= M;
        }
    }
}

impl<const M: u32> Mul for ModularType<M> {
    type Output = ModularType<M>;

    fn mul(self, rhs: Self) -> Self::Output {
        Self((self.0 as u64 * rhs.0 as u64 % M as u64) as u32)
    }
}

impl<const M: u32> Neg for ModularType<M> {
    type Output = ModularType<M>;

    fn neg(self) -> Self::Output {
        Self(if self.0 == 0 { 0 } else { M - self.0 })
    }
}

impl<const M: u32> From<u32> for ModularType<M> {
    fn from(x: u32) -> Self {
        Self(x % M)
    }
}

impl<const M: u32> From<i32> for ModularType<M> {
    fn from(x: i32) -> Self {
        Self(x.rem_euclid(M as i32) as u32)
    }
}

impl<const M: u32> From<usize> for ModularType<M> {
    fn from(x: usize) -> Self {
        Self((x % M as usize) as u32)
    }
}

impl<const M: u32> Into<usize> for ModularType<M> {
    fn into(self) -> usize {
        self.0 as usize
    }
}

impl<const M: u32> Writable for ModularType<M> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = crate::io::input::Input::new(&mut sin);
    unsafe {
        crate::io::output::OUTPUT = Some(crate::io::output::Output::new(Box::new(std::io::stdout())));
    }
    crate::solution::run(input);
}


type Mod = ModInt1000000007;
fn main() {
    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());
    #[allow(unused_macros)] macro_rules! print { ($($tt:tt)*) => {{ use std::io::Write; std::write!(writer, $($tt)*).unwrap(); }}; }
    #[allow(unused_macros)] macro_rules! println { ($($tt:tt)*) => {{ use std::io::Write; std::writeln!(writer, $($tt)*).unwrap(); }}; }

    let mut precalc = Binom::<Mod>::new();
    input! {
        n: usize,
        k: usize
    }
    let k = k.min(n);
    let mut ans = Mod::raw(0);
    for i in 0..=k {
        ans += precalc.binom(n, i);
    }
    println!("{}", ans);
}

struct Binom<T> {
    len: usize,
    inv: Vec<usize>,
    fact: Vec<T>,
    ifact: Vec<T>,
    n: Option<usize>,
    nprod: Vec<T>,
    m: Option<usize>,
    mprod_n: usize,
    mprod: T
}

#[allow(dead_code)]
impl<T: ModIntBase + std::iter::Product> Binom<T> {
    pub fn new() -> Self {
        assert_eq!(std::mem::size_of::<usize>(), 8);

        Self {
            len: 1,
            inv: vec![0, 1],
            fact: vec![T::raw(1), T::raw(1)],
            ifact: vec![T::raw(1), T::raw(1)],
            n: None,
            nprod: vec![],
            m: None,
            mprod_n: 0,
            mprod: T::raw(0)
        }
    }

    fn ensure(&mut self, idx: usize) {
        if idx > self.len {
            self.inv.reserve(idx - self.len);
            self.fact.reserve(idx - self.len);
            self.ifact.reserve(idx - self.len);
            let m = T::modulus() as usize;
            for i in self.len+1..=idx {
                let inv_i = self.inv[m % i] * (m - m / i) % m;
                self.inv.push(inv_i);
                self.fact.push(self.fact[i - 1] * T::from(i));
                self.ifact.push(self.ifact[i - 1] * T::raw(inv_i as u32));
            }
            self.len = idx;
        }
    }

    pub fn binom(&mut self, n: usize, m: usize) -> T {
        if m > n {
            return T::raw(0)
        }
        if m == 0 || m == n {
            return T::raw(1)
        }
        self.ensure(n);
        self.fact[n] * self.ifact[m] * self.ifact[n - m]
    }

    pub fn binom_n(&mut self, n: usize, m: usize) -> T {
        if m > n {
            return T::raw(0)
        }
        if m == 0 || m == n {
            return T::raw(1)
        }
        if n >= T::modulus() as usize {
            return self.binom_n(n % T::modulus() as usize, m);
        }
        if self.n != Some(n) {
            self.n = Some(n);
            self.nprod = vec![T::from(n)];
        }
        for i in self.nprod.len()..m {
            self.nprod.push(self.nprod[i - 1] * T::from(n - i));
        }
        self.ensure(m);
        self.nprod[m - 1] * self.ifact[m]
    }

    pub fn binom_m(&mut self, n: usize, m: usize) -> T {
        if m > n {
            return T::raw(0)
        }
        if m == 0 || m == n {
            return T::raw(1)
        }
        if n >= T::modulus() as usize {
            return self.binom_m(n % T::modulus() as usize, m);
        }
        if self.m != Some(m) || self.mprod_n > n + m || self.mprod_n + m < n {
            self.m = Some(m);
            self.mprod_n = n;
            self.mprod = ((n-m+1)..=n).map(T::from).product::<T>();
        } else {
            while self.mprod_n < n {
                self.mprod_n += 1;
                self.mprod *= T::from(self.mprod_n);
                self.mprod /= T::from(self.mprod_n - m);
            }
            while self.mprod_n > n {
                self.mprod /= T::from(self.mprod_n);
                self.mprod *= T::from(self.mprod_n - m);
                self.mprod_n -= 1;
            }
        }
        self.ensure(m);
        self.mprod * self.ifact[m]
    }

}

// input macro with modifications (to better align with proconio)
// based on https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

#[macro_export]
macro_rules! input {
    (@lock_stdin $reader:ident) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut $reader = move || -> String {
            unsafe {
                String::from_utf8_unchecked(
                    bytes
                        .by_ref()
                        .map_while(Result::ok)
                        .skip_while(|c| c.is_ascii_whitespace())
                        .take_while(|c| !c.is_ascii_whitespace())
                        .collect()
                )
            }
        };
    };

    (@inner $reader:ident) => {};
    (@inner $reader:ident, ) => {};

    (@inner $reader:ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($reader, $t);
        input!{@inner $reader $($r)*}
    };

    (@inner $reader:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($reader, $t);
        input!{@inner $reader $($r)*}
    };

    (@inner $reader:ident $($r:tt)*) => {
        compile_error!(stringify!(unable to read $($r)*))
    };

    (line = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_ascii_whitespace();
        let mut next = || { iter.next().unwrap_or_default() };
        input!{@inner next, $($r)*}
    };
    (name = $reader:ident, $($r:tt)*) => {
        input!{@lock_stdin $reader};
        input!{@inner $reader, $($r)*}
    };
    (use $reader:ident, $($r:tt)*) => {
        input!{@inner $reader, $($r)*}
    };
    ($($r:tt)*) => {
        input!{@lock_stdin reader};
        input!{@inner reader, $($r)*};
    };
}

#[macro_export]
macro_rules! read_value {
    ($reader:ident, ( $($t:tt),* )) => {
        ( $(read_value!($reader, $t)),* )
    };

    ($reader:ident, [ $t:tt ]) => {{
        let len = read_value!($reader, usize);
        read_value!($reader, [ $t ; len])
    }};

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

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

    ($reader:ident, bytes) => {
        read_value!($reader, String).into_bytes()
    };

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

    ($reader:ident, $t:tt) => {
        $reader().parse::<$t>().expect(stringify!(parse error($t)))
    };
}

//https://github.com/rust-lang-ja/ac-library-rs

pub mod internal_math {
    #![allow(dead_code)]
    use std::mem::swap;

    pub(crate) fn safe_mod(mut x: i64, m: i64) -> i64 {
        x %= m;
        if x < 0 {
            x += m;
        }
        x
    }

    pub(crate) struct Barrett {
        pub(crate) _m: u32,
        pub(crate) im: u64,
    }

    impl Barrett {
        pub(crate) fn new(m: u32) -> Barrett {
            Barrett {
                _m: m,
                im: (-1i64 as u64 / m as u64).wrapping_add(1),
            }
        }

        pub(crate) fn umod(&self) -> u32 {
            self._m
        }

        #[allow(clippy::many_single_char_names)]
        pub(crate) fn mul(&self, a: u32, b: u32) -> u32 {
            mul_mod(a, b, self._m, self.im)
        }
    }

    #[allow(clippy::many_single_char_names)]
    pub(crate) fn mul_mod(a: u32, b: u32, m: u32, im: u64) -> u32 {
        let mut z = a as u64;
        z *= b as u64;
        let x = (((z as u128) * (im as u128)) >> 64) as u64;
        let mut v = z.wrapping_sub(x.wrapping_mul(m as u64)) as u32;
        if m <= v {
            v = v.wrapping_add(m);
        }
        v
    }

    #[allow(clippy::many_single_char_names)]
    pub(crate) fn pow_mod(x: i64, mut n: i64, m: i32) -> i64 {
        if m == 1 {
            return 0;
        }
        let _m = m as u32;
        let mut r: u64 = 1;
        let mut y: u64 = safe_mod(x, m as i64) as u64;
        while n != 0 {
            if (n & 1) > 0 {
                r = (r * y) % (_m as u64);
            }
            y = (y * y) % (_m as u64);
            n >>= 1;
        }
        r as i64
    }

    pub(crate) fn is_prime(n: i32) -> bool {
        let n = n as i64;
        match n {
            _ if n <= 1 => return false,
            2 | 7 | 61 => return true,
            _ if n % 2 == 0 => return false,
            _ => {}
        }
        let mut d = n - 1;
        while d % 2 == 0 {
            d /= 2;
        }
        for &a in &[2, 7, 61] {
            let mut t = d;
            let mut y = pow_mod(a, t, n as i32);
            while t != n - 1 && y != 1 && y != n - 1 {
                y = y * y % n;
                t <<= 1;
            }
            if y != n - 1 && t % 2 == 0 {
                return false;
            }
        }
        true
    }

    #[allow(clippy::many_single_char_names)]
    pub(crate) fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
        let a = safe_mod(a, b);
        if a == 0 {
            return (b, 0);
        }

        let mut s = b;
        let mut t = a;
        let mut m0 = 0;
        let mut m1 = 1;

        while t != 0 {
            let u = s / t;
            s -= t * u;
            m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b

            swap(&mut s, &mut t);
            swap(&mut m0, &mut m1);
        }
        if m0 < 0 {
            m0 += b / s;
        }
        (s, m0)
    }

    pub(crate) fn primitive_root(m: i32) -> i32 {
        match m {
            2 => return 1,
            167_772_161 => return 3,
            469_762_049 => return 3,
            754_974_721 => return 11,
            998_244_353 => return 3,
            _ => {}
        }

        let mut divs = [0; 20];
        divs[0] = 2;
        let mut cnt = 1;
        let mut x = (m - 1) / 2;
        while x % 2 == 0 {
            x /= 2;
        }
        for i in (3..std::i32::MAX).step_by(2) {
            if i as i64 * i as i64 > x as i64 {
                break;
            }
            if x % i == 0 {
                divs[cnt] = i;
                cnt += 1;
                while x % i == 0 {
                    x /= i;
                }
            }
        }
        if x > 1 {
            divs[cnt] = x;
            cnt += 1;
        }
        let mut g = 2;
        loop {
            if (0..cnt).all(|i| pow_mod(g, ((m - 1) / divs[i]) as i64, m) != 1) {
                break g as i32;
            }
            g += 1;
        }
    }
}
pub mod modint {

    use crate::internal_math;
    use std::{
        cell::RefCell,
        convert::{Infallible, TryInto as _},
        fmt,
        hash::{Hash, Hasher},
        iter::{Product, Sum},
        marker::PhantomData,
        ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign},
        str::FromStr,
        sync::atomic::{self, AtomicU32, AtomicU64},
        thread::LocalKey,
    };

    pub type ModInt1000000007 = StaticModInt<Mod1000000007>;
    pub type ModInt998244353 = StaticModInt<Mod998244353>;
    pub type ModInt = DynamicModInt<DefaultId>;

    #[derive(Copy, Clone, Eq, PartialEq)]
    #[repr(transparent)]
    pub struct StaticModInt<M> {
        val: u32,
        phantom: PhantomData<fn() -> M>,
    }

    impl<M: Modulus> StaticModInt<M> {
        #[inline(always)]
        pub fn modulus() -> u32 {
            M::VALUE
        }

        #[inline]
        pub fn new<T: RemEuclidU32>(val: T) -> Self {
            Self::raw(val.rem_euclid_u32(M::VALUE))
        }

        #[inline]
        pub fn raw(val: u32) -> Self {
            Self {
                val,
                phantom: PhantomData,
            }
        }

        #[inline]
        pub fn val(self) -> u32 {
            self.val
        }

        #[inline]
        pub fn pow(self, n: u64) -> Self {
            <Self as ModIntBase>::pow(self, n)
        }

        #[inline]
        pub fn inv(self) -> Self {
            if M::HINT_VALUE_IS_PRIME {
                if self.val() == 0 {
                    panic!("attempt to divide by zero");
                }
                debug_assert!(
                    internal_math::is_prime(M::VALUE.try_into().unwrap()),
                    "{} is not a prime number",
                    M::VALUE,
                );
                self.pow((M::VALUE - 2).into())
            } else {
                Self::inv_for_non_prime_modulus(self)
            }
        }
    }

    impl<M: Modulus> ModIntBase for StaticModInt<M> {
        #[inline(always)]
        fn modulus() -> u32 {
            Self::modulus()
        }

        #[inline]
        fn raw(val: u32) -> Self {
            Self::raw(val)
        }

        #[inline]
        fn val(self) -> u32 {
            self.val()
        }

        #[inline]
        fn inv(self) -> Self {
            self.inv()
        }
    }

    pub trait Modulus: 'static + Copy + Eq {
        const VALUE: u32;
        const HINT_VALUE_IS_PRIME: bool;

        fn butterfly_cache() -> &'static LocalKey<RefCell<Option<ButterflyCache<Self>>>>;
    }

    #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
    pub enum Mod1000000007 {}

    impl Modulus for Mod1000000007 {
        const VALUE: u32 = 1_000_000_007;
        const HINT_VALUE_IS_PRIME: bool = true;

        fn butterfly_cache() -> &'static LocalKey<RefCell<Option<ButterflyCache<Self>>>> {
            thread_local! {
                static BUTTERFLY_CACHE: RefCell<Option<ButterflyCache<Mod1000000007>>> = RefCell::default();
            }
            &BUTTERFLY_CACHE
        }
    }

    #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
    pub enum Mod998244353 {}

    impl Modulus for Mod998244353 {
        const VALUE: u32 = 998_244_353;
        const HINT_VALUE_IS_PRIME: bool = true;

        fn butterfly_cache() -> &'static LocalKey<RefCell<Option<ButterflyCache<Self>>>> {
            thread_local! {
                static BUTTERFLY_CACHE: RefCell<Option<ButterflyCache<Mod998244353>>> = RefCell::default();
            }
            &BUTTERFLY_CACHE
        }
    }

    #[allow(dead_code)]
    pub struct ButterflyCache<M> {
        pub(crate) sum_e: Vec<StaticModInt<M>>,
        pub(crate) sum_ie: Vec<StaticModInt<M>>,
    }

    #[derive(Copy, Clone, Eq, PartialEq)]
    #[repr(transparent)]
    pub struct DynamicModInt<I> {
        val: u32,
        phantom: PhantomData<fn() -> I>,
    }

    impl<I: Id> DynamicModInt<I> {
        #[inline]
        pub fn modulus() -> u32 {
            I::companion_barrett().umod()
        }

        #[inline]
        pub fn set_modulus(modulus: u32) {
            if modulus == 0 {
                panic!("the modulus must not be 0");
            }
            I::companion_barrett().update(modulus);
        }

        #[inline]
        pub fn new<T: RemEuclidU32>(val: T) -> Self {
            <Self as ModIntBase>::new(val)
        }

        #[inline]
        pub fn raw(val: u32) -> Self {
            Self {
                val,
                phantom: PhantomData,
            }
        }

        #[inline]
        pub fn val(self) -> u32 {
            self.val
        }

        #[inline]
        pub fn pow(self, n: u64) -> Self {
            <Self as ModIntBase>::pow(self, n)
        }

        #[inline]
        pub fn inv(self) -> Self {
            Self::inv_for_non_prime_modulus(self)
        }
    }

    impl<I: Id> ModIntBase for DynamicModInt<I> {
        #[inline]
        fn modulus() -> u32 {
            Self::modulus()
        }

        #[inline]
        fn raw(val: u32) -> Self {
            Self::raw(val)
        }

        #[inline]
        fn val(self) -> u32 {
            self.val()
        }

        #[inline]
        fn inv(self) -> Self {
            self.inv()
        }
    }

    pub trait Id: 'static + Copy + Eq {
        fn companion_barrett() -> &'static Barrett;
    }

    #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
    pub enum DefaultId {}

    impl Id for DefaultId {
        fn companion_barrett() -> &'static Barrett {
            static BARRETT: Barrett = Barrett::default();
            &BARRETT
        }
    }

    pub struct Barrett {
        m: AtomicU32,
        im: AtomicU64,
    }

    impl Barrett {
        #[inline]
        pub const fn new(m: u32) -> Self {
            Self {
                m: AtomicU32::new(m),
                im: AtomicU64::new((-1i64 as u64 / m as u64).wrapping_add(1)),
            }
        }

        #[inline]
        const fn default() -> Self {
            Self::new(998_244_353)
        }

        #[inline]
        fn update(&self, m: u32) {
            let im = (-1i64 as u64 / m as u64).wrapping_add(1);
            self.m.store(m, atomic::Ordering::SeqCst);
            self.im.store(im, atomic::Ordering::SeqCst);
        }

        #[inline]
        fn umod(&self) -> u32 {
            self.m.load(atomic::Ordering::SeqCst)
        }

        #[inline]
        fn mul(&self, a: u32, b: u32) -> u32 {
            let m = self.m.load(atomic::Ordering::SeqCst);
            let im = self.im.load(atomic::Ordering::SeqCst);
            internal_math::mul_mod(a, b, m, im)
        }
    }

    impl Default for Barrett {
        #[inline]
        fn default() -> Self {
            Self::default()
        }
    }

    pub trait ModIntBase:
        Default
        + FromStr
        + From<i8>
        + From<i16>
        + From<i32>
        + From<i64>
        + From<i128>
        + From<isize>
        + From<u8>
        + From<u16>
        + From<u32>
        + From<u64>
        + From<u128>
        + From<usize>
        + Copy
        + Eq
        + Hash
        + fmt::Display
        + fmt::Debug
        + Neg<Output = Self>
        + Add<Output = Self>
        + Sub<Output = Self>
        + Mul<Output = Self>
        + Div<Output = Self>
        + AddAssign
        + SubAssign
        + MulAssign
        + DivAssign
    {
        fn modulus() -> u32;

        fn raw(val: u32) -> Self;

        fn val(self) -> u32;

        fn inv(self) -> Self;

        #[inline]
        fn new<T: RemEuclidU32>(val: T) -> Self {
            Self::raw(val.rem_euclid_u32(Self::modulus()))
        }

        #[inline]
        fn pow(self, mut n: u64) -> Self {
            let mut x = self;
            let mut r = Self::raw(1);
            while n > 0 {
                if n & 1 == 1 {
                    r *= x;
                }
                x *= x;
                n >>= 1;
            }
            r
        }
    }

    pub trait RemEuclidU32 {
        fn rem_euclid_u32(self, modulus: u32) -> u32;
    }

    macro_rules! impl_rem_euclid_u32_for_small_signed {
    ($($ty:tt),*) => {
        $(
            impl RemEuclidU32 for $ty {
                #[inline]
                fn rem_euclid_u32(self, modulus: u32) -> u32 {
                    (self as i64).rem_euclid(i64::from(modulus)) as _
                }
            }
        )*
    }
}

    impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);

    impl RemEuclidU32 for i128 {
        #[inline]
        fn rem_euclid_u32(self, modulus: u32) -> u32 {
            self.rem_euclid(i128::from(modulus)) as _
        }
    }

    macro_rules! impl_rem_euclid_u32_for_small_unsigned {
    ($($ty:tt),*) => {
        $(
            impl RemEuclidU32 for $ty {
                #[inline]
                fn rem_euclid_u32(self, modulus: u32) -> u32 {
                    self as u32 % modulus
                }
            }
        )*
    }
}

    macro_rules! impl_rem_euclid_u32_for_large_unsigned {
    ($($ty:tt),*) => {
        $(
            impl RemEuclidU32 for $ty {
                #[inline]
                fn rem_euclid_u32(self, modulus: u32) -> u32 {
                    (self % (modulus as $ty)) as _
                }
            }
        )*
    }
}

    impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);
    impl_rem_euclid_u32_for_large_unsigned!(u64, u128);

    #[cfg(target_pointer_width = "32")]
    impl_rem_euclid_u32_for_small_unsigned!(usize);

    #[cfg(target_pointer_width = "64")]
    impl_rem_euclid_u32_for_large_unsigned!(usize);

    trait InternalImplementations: ModIntBase {
        #[inline]
        fn inv_for_non_prime_modulus(this: Self) -> Self {
            let (gcd, x) = internal_math::inv_gcd(this.val().into(), Self::modulus().into());
            if gcd != 1 {
                panic!("the multiplicative inverse does not exist");
            }
            Self::new(x)
        }

        #[inline]
        fn default_impl() -> Self {
            Self::raw(0)
        }

        #[inline]
        fn from_str_impl(s: &str) -> Result<Self, Infallible> {
            Ok(s.parse::<i64>()
                .map(Self::new)
                .unwrap_or_else(|_| todo!("parsing as an arbitrary precision integer?")))
        }

        #[inline]
        fn hash_impl(this: &Self, state: &mut impl Hasher) {
            this.val().hash(state)
        }

        #[inline]
        fn display_impl(this: &Self, f: &mut fmt::Formatter) -> fmt::Result {
            fmt::Display::fmt(&this.val(), f)
        }

        #[inline]
        fn debug_impl(this: &Self, f: &mut fmt::Formatter) -> fmt::Result {
            fmt::Debug::fmt(&this.val(), f)
        }

        #[inline]
        fn neg_impl(this: Self) -> Self {
            Self::sub_impl(Self::raw(0), this)
        }

        #[inline]
        fn add_impl(lhs: Self, rhs: Self) -> Self {
            let modulus = Self::modulus();
            let mut val = lhs.val() + rhs.val();
            if val >= modulus {
                val -= modulus;
            }
            Self::raw(val)
        }

        #[inline]
        fn sub_impl(lhs: Self, rhs: Self) -> Self {
            let modulus = Self::modulus();
            let mut val = lhs.val().wrapping_sub(rhs.val());
            if val >= modulus {
                val = val.wrapping_add(modulus)
            }
            Self::raw(val)
        }

        fn mul_impl(lhs: Self, rhs: Self) -> Self;

        #[inline]
        fn div_impl(lhs: Self, rhs: Self) -> Self {
            Self::mul_impl(lhs, rhs.inv())
        }
    }

    impl<M: Modulus> InternalImplementations for StaticModInt<M> {
        #[inline]
        fn mul_impl(lhs: Self, rhs: Self) -> Self {
            Self::raw((u64::from(lhs.val()) * u64::from(rhs.val()) % u64::from(M::VALUE)) as u32)
        }
    }

    impl<I: Id> InternalImplementations for DynamicModInt<I> {
        #[inline]
        fn mul_impl(lhs: Self, rhs: Self) -> Self {
            Self::raw(I::companion_barrett().mul(lhs.val, rhs.val))
        }
    }

    macro_rules! impl_basic_traits {
    () => {};
    (impl <$generic_param:ident : $generic_param_bound:tt> _ for $self:ty; $($rest:tt)*) => {
        impl <$generic_param: $generic_param_bound> Default for $self {
            #[inline]
            fn default() -> Self {
                Self::default_impl()
            }
        }

        impl <$generic_param: $generic_param_bound> FromStr for $self {
            type Err = Infallible;

            #[inline]
            fn from_str(s: &str) -> Result<Self, Infallible> {
                Self::from_str_impl(s)
            }
        }

        impl<$generic_param: $generic_param_bound, V: RemEuclidU32> From<V> for $self {
            #[inline]
            fn from(from: V) -> Self {
                Self::new(from)
            }
        }

        #[allow(clippy::derive_hash_xor_eq)]
        impl<$generic_param: $generic_param_bound> Hash for $self {
            #[inline]
            fn hash<H: Hasher>(&self, state: &mut H) {
                Self::hash_impl(self, state)
            }
        }

        impl<$generic_param: $generic_param_bound> fmt::Display for $self {
            #[inline]
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                Self::display_impl(self, f)
            }
        }

        impl<$generic_param: $generic_param_bound> fmt::Debug for $self {
            #[inline]
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                Self::debug_impl(self, f)
            }
        }

        impl<$generic_param: $generic_param_bound> Neg for $self {
            type Output = $self;

            #[inline]
            fn neg(self) -> $self {
                Self::neg_impl(self)
            }
        }

        impl<$generic_param: $generic_param_bound> Neg for &'_ $self {
            type Output = $self;

            #[inline]
            fn neg(self) -> $self {
                <$self>::neg_impl(*self)
            }
        }

        impl_basic_traits!($($rest)*);
    };
}

    impl_basic_traits! {
        impl <M: Modulus> _ for StaticModInt<M> ;
        impl <I: Id     > _ for DynamicModInt<I>;
    }

    macro_rules! impl_bin_ops {
    () => {};
    (for<$($generic_param:ident : $generic_param_bound:tt),*> <$lhs_ty:ty> ~ <$rhs_ty:ty> -> $output:ty { { $lhs_body:expr } ~ { $rhs_body:expr } } $($rest:tt)*) => {
        impl <$($generic_param: $generic_param_bound),*> Add<$rhs_ty> for $lhs_ty {
            type Output = $output;

            #[inline]
            fn add(self, rhs: $rhs_ty) -> $output {
                <$output>::add_impl(apply($lhs_body, self), apply($rhs_body, rhs))
            }
        }

        impl <$($generic_param: $generic_param_bound),*> Sub<$rhs_ty> for $lhs_ty {
            type Output = $output;

            #[inline]
            fn sub(self, rhs: $rhs_ty) -> $output {
                <$output>::sub_impl(apply($lhs_body, self), apply($rhs_body, rhs))
            }
        }

        impl <$($generic_param: $generic_param_bound),*> Mul<$rhs_ty> for $lhs_ty {
            type Output = $output;

            #[inline]
            fn mul(self, rhs: $rhs_ty) -> $output {
                <$output>::mul_impl(apply($lhs_body, self), apply($rhs_body, rhs))
            }
        }

        impl <$($generic_param: $generic_param_bound),*> Div<$rhs_ty> for $lhs_ty {
            type Output = $output;

            #[inline]
            fn div(self, rhs: $rhs_ty) -> $output {
                <$output>::div_impl(apply($lhs_body, self), apply($rhs_body, rhs))
            }
        }

        impl_bin_ops!($($rest)*);
    };
}

    macro_rules! impl_assign_ops {
    () => {};
    (for<$($generic_param:ident : $generic_param_bound:tt),*> <$lhs_ty:ty> ~= <$rhs_ty:ty> { _ ~= { $rhs_body:expr } } $($rest:tt)*) => {
        impl <$($generic_param: $generic_param_bound),*> AddAssign<$rhs_ty> for $lhs_ty {
            #[inline]
            fn add_assign(&mut self, rhs: $rhs_ty) {
                *self = *self + apply($rhs_body, rhs);
            }
        }

        impl <$($generic_param: $generic_param_bound),*> SubAssign<$rhs_ty> for $lhs_ty {
            #[inline]
            fn sub_assign(&mut self, rhs: $rhs_ty) {
                *self = *self - apply($rhs_body, rhs);
            }
        }

        impl <$($generic_param: $generic_param_bound),*> MulAssign<$rhs_ty> for $lhs_ty {
            #[inline]
            fn mul_assign(&mut self, rhs: $rhs_ty) {
                *self = *self * apply($rhs_body, rhs);
            }
        }

        impl <$($generic_param: $generic_param_bound),*> DivAssign<$rhs_ty> for $lhs_ty {
            #[inline]
            fn div_assign(&mut self, rhs: $rhs_ty) {
                *self = *self / apply($rhs_body, rhs);
            }
        }

        impl_assign_ops!($($rest)*);
    };
}

    #[inline]
    fn apply<F: FnOnce(X) -> O, X, O>(f: F, x: X) -> O {
        f(x)
    }

    impl_bin_ops! {
        for<M: Modulus> <StaticModInt<M>     > ~ <StaticModInt<M>     > -> StaticModInt<M>  { { |x| x  } ~ { |x| x  } }
        for<M: Modulus> <StaticModInt<M>     > ~ <&'_ StaticModInt<M> > -> StaticModInt<M>  { { |x| x  } ~ { |&x| x } }
        for<M: Modulus> <&'_ StaticModInt<M> > ~ <StaticModInt<M>     > -> StaticModInt<M>  { { |&x| x } ~ { |x| x  } }
        for<M: Modulus> <&'_ StaticModInt<M> > ~ <&'_ StaticModInt<M> > -> StaticModInt<M>  { { |&x| x } ~ { |&x| x } }
        for<I: Id     > <DynamicModInt<I>    > ~ <DynamicModInt<I>    > -> DynamicModInt<I> { { |x| x  } ~ { |x| x  } }
        for<I: Id     > <DynamicModInt<I>    > ~ <&'_ DynamicModInt<I>> -> DynamicModInt<I> { { |x| x  } ~ { |&x| x } }
        for<I: Id     > <&'_ DynamicModInt<I>> ~ <DynamicModInt<I>    > -> DynamicModInt<I> { { |&x| x } ~ { |x| x  } }
        for<I: Id     > <&'_ DynamicModInt<I>> ~ <&'_ DynamicModInt<I>> -> DynamicModInt<I> { { |&x| x } ~ { |&x| x } }

        for<M: Modulus, T: RemEuclidU32> <StaticModInt<M>     > ~ <T> -> StaticModInt<M>  { { |x| x  } ~ { StaticModInt::<M>::new } }
        for<I: Id     , T: RemEuclidU32> <DynamicModInt<I>    > ~ <T> -> DynamicModInt<I> { { |x| x  } ~ { DynamicModInt::<I>::new } }
    }

    impl_assign_ops! {
        for<M: Modulus> <StaticModInt<M> > ~= <StaticModInt<M>     > { _ ~= { |x| x  } }
        for<M: Modulus> <StaticModInt<M> > ~= <&'_ StaticModInt<M> > { _ ~= { |&x| x } }
        for<I: Id     > <DynamicModInt<I>> ~= <DynamicModInt<I>    > { _ ~= { |x| x  } }
        for<I: Id     > <DynamicModInt<I>> ~= <&'_ DynamicModInt<I>> { _ ~= { |&x| x } }

        for<M: Modulus, T: RemEuclidU32> <StaticModInt<M> > ~= <T> { _ ~= { StaticModInt::<M>::new } }
        for<I: Id,      T: RemEuclidU32> <DynamicModInt<I>> ~= <T> { _ ~= { DynamicModInt::<I>::new } }
    }

    macro_rules! impl_folding {
    () => {};
    (impl<$generic_param:ident : $generic_param_bound:tt> $trait:ident<_> for $self:ty { fn $method:ident(_) -> _ { _($unit:expr, $op:expr) } } $($rest:tt)*) => {
        impl<$generic_param: $generic_param_bound> $trait<Self> for $self {
            #[inline]
            fn $method<S>(iter: S) -> Self
            where
                S: Iterator<Item = Self>,
            {
                iter.fold($unit, $op)
            }
        }

        impl<'a, $generic_param: $generic_param_bound> $trait<&'a Self> for $self {
            #[inline]
            fn $method<S>(iter: S) -> Self
            where
                S: Iterator<Item = &'a Self>,
            {
                iter.fold($unit, $op)
            }
        }

        impl_folding!($($rest)*);
    };
}

    impl_folding! {
        impl<M: Modulus> Sum<_>     for StaticModInt<M>  { fn sum(_)     -> _ { _(Self::raw(0), Add::add) } }
        impl<M: Modulus> Product<_> for StaticModInt<M>  { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }
        impl<I: Id     > Sum<_>     for DynamicModInt<I> { fn sum(_)     -> _ { _(Self::raw(0), Add::add) } }
        impl<I: Id     > Product<_> for DynamicModInt<I> { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }
    }
}
use modint::*;


fn main() {
    let v: Vec<i32> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect()
    };

    let min_num = v.iter().min().unwrap();
    if min_num % 2 == 0 {
        println!("Malvika");
    } else {
        println!("Akshat");
    }
}


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 main() {
    let mut scan = Scan::new();
    let a: usize = scan.next();
    let b: usize = scan.next();
    let c = a.min(b);
    println!("{}", if c % 2 == 0 { "Malvika" } else { "Akshat"});
}


use std::io::*;

fn main () {
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let mut it = input.split_whitespace();
    let n: i32= it.next().unwrap().parse().unwrap();
    let pos: i32 = it.next().unwrap().parse().unwrap();
    let l: i32 = it.next().unwrap().parse().unwrap();
    let r: i32 = it.next().unwrap().parse().unwrap();

    let rl = l != 1;
    let rr = r != n;
    let mut steps = 0;

    if rl && rr {
        steps = 2 + (pos - l).abs().min((pos - r).abs()) + (r - l);
    } else if !rl && rr {
        steps = 1 + (pos - r).abs();
    } else if !rr && rl{
        steps = 1 +(pos - l).abs();
    }

    println!("{}", steps);

}


use std::io::{self, prelude::*, BufWriter};
use std::str::FromStr;

type M = DynamicModInt;

#[allow(unused)]
fn solve2<R: BufRead, W: Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: usize = scan.next();
    M::set_modulus(scan.next());

    let mut dp = vec![M::zero(); n + 1];
    dp[1] = M::one();
    let mut sum = M::one();
    for i in 2..=n {
        let root = (i as f64).sqrt() as usize;
        for j in 2..=root {
            let delta = dp[i / j];
            dp[i] += delta;
        }
        for k in 1..i / root {
            let high = i / k;
            let low = i / (k + 1) + 1;
            if low <= high {
                let delta = dp[k] * M::from(high - low + 1);
                dp[i] += delta;
            }
        }

        dp[i] += sum;
        sum += dp[i];
    }
    writeln!(out, "{}", dp[n]).ok();
}

fn solve<R: BufRead, W: Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: usize = scan.next();
    DynamicModInt::set_modulus(scan.next());

    let mut dp = vec![M::zero(); n + 1];
    dp[1] = M::one();
    for i in 2..=n {
        if i == 2 {
            dp[2] = M::two();
        } else {
            let delta = M::two() * dp[i - 1];
            dp[i] += delta;
            let delta = dp[1];
            dp[i] += delta;
        }
        for j in (i + i..=n).step_by(i) {
            let delta = dp[i] - dp[i - 1];
            dp[j] += delta;
        }
    }
    writeln!(out, "{}", dp[n]).ok();
}

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

    let tests = 1; // scan.next::<usize>();
    for _ in 0..tests {
        solve(&mut scan, &mut out);
    }
}

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

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

    pub fn next<T: FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().unwrap();
            }
            let mut line = String::new();
            self.reader.read_line(&mut line).unwrap();
            self.buffer = line
                .split_ascii_whitespace()
                .rev()
                .map(String::from)
                .collect();
        }
    }

    pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
}
// }}}
// {{{ DynamicModInt
use std::fmt;
use std::iter::{Product, Sum};
use std::ops::*;

#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash)]
pub struct DynamicModInt(pub i32);

impl Default for DynamicModInt {
    fn default() -> Self {
        DynamicModInt(0)
    }
}

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

impl DynamicModInt {
    pub fn set_modulus(modulus: i32) {
        *Self::modulus_ref() = modulus;
    }

    pub fn modulus() -> i32 {
        *Self::modulus_ref()
    }

    fn modulus_ref() -> &'static mut i32 {
        static mut MODULES: i32 = 0;
        return unsafe { &mut MODULES };
    }

    pub fn raw(val: i32) -> Self {
        DynamicModInt(val)
    }

    #[inline]
    fn canon(val: i32) -> Self {
        DynamicModInt(if val < 0 { val + Self::modulus() } else { val })
    }

    #[inline]
    pub fn zero() -> Self {
        DynamicModInt(0)
    }

    #[inline]
    pub fn one() -> Self {
        DynamicModInt(1)
    }

    #[inline]
    pub fn two() -> Self {
        DynamicModInt(2)
    }

    pub fn pow(self, n: u64) -> Self {
        let mut n = n;
        let mut res = Self::one();
        let mut a = self;
        while n > 0 {
            if n & 1 == 1 {
                res = res * a;
            }
            a = a * a;
            n >>= 1;
        }

        res
    }

    pub fn inv(self) -> Self {
        self.pow(Self::modulus() as u64 - 2)
    }
}

macro_rules! from_bigger_int {
    ($($int:ident)*) => {$(
        impl From<$int> for DynamicModInt {
            fn from(val: $int) -> Self {
                Self::canon((val % Self::modulus() as $int) as i32)
            }
        }
    )*};
}
from_bigger_int!(u32 usize i64 u64 i128 u128);

macro_rules! from_smaller_int {
    ($($int: ident)*) => {$(
        impl From<$int> for DynamicModInt {
            fn from(val: $int) -> Self {
                Self::canon(val as i32 % Self::modulus())
            }
        }
    )*}
}
from_smaller_int!(i32 i16 u16 i8 u8);

impl Neg for DynamicModInt {
    type Output = Self;
    fn neg(self) -> Self {
        DynamicModInt(if self.0 == 0 {
            0
        } else {
            Self::modulus() - self.0
        })
    }
}

impl Add for DynamicModInt {
    type Output = Self;
    fn add(self, other: Self) -> Self {
        let s = self.0 + other.0;
        let m = Self::modulus();
        DynamicModInt(if s >= m { s - m } else { s })
    }
}

impl Sub for DynamicModInt {
    type Output = Self;
    fn sub(self, other: Self) -> Self {
        Self::canon(self.0 - other.0)
    }
}

impl Mul for DynamicModInt {
    type Output = Self;
    fn mul(self, other: Self) -> Self {
        let mul: u64 = (self.0 as u64 * other.0 as u64) % Self::modulus() as u64;
        DynamicModInt(mul as i32)
    }
}

impl Div for DynamicModInt {
    type Output = Self;
    fn div(self, other: Self) -> Self {
        self * other.inv()
    }
}

impl AddAssign for DynamicModInt {
    fn add_assign(&mut self, other: Self) {
        *self = *self + other;
    }
}

impl SubAssign for DynamicModInt {
    fn sub_assign(&mut self, other: Self) {
        *self = *self - other;
    }
}

impl MulAssign for DynamicModInt {
    fn mul_assign(&mut self, other: Self) {
        *self = *self * other;
    }
}

impl DivAssign for DynamicModInt {
    fn div_assign(&mut self, other: Self) {
        *self = *self / other;
    }
}

impl Sum for DynamicModInt {
    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Self::zero(), Add::add)
    }
}

impl Product for DynamicModInt {
    fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Self::one(), Mul::mul)
    }
}
// }}}


use std::{cell::Cell, cmp::{Reverse, max, min}, collections::{BTreeMap, HashMap, HashSet}, error::Error, fmt::Display, io::{BufWriter, Read, Write}, iter::Peekable, mem::swap, ops::{Not, Range, RangeInclusive, Sub}, process::exit, rc::Rc, str::{FromStr, from_utf8, from_utf8_unchecked}};

const IO_BUF_SIZE: usize = 1 << 16;
struct Scanner<'a, R: Read> {
    src: &'a mut R,
    _buf: Vec<u8>,
    _pt: usize, // pointer
    _rd: usize, // bytes read
}

#[allow(dead_code)]
impl<'a, R: Read> Scanner<'a, R> {
    fn new(src: &'a mut R) -> Scanner<'a, R> {
        Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }
    }

    fn _check_buf(&mut self) {
        if self._pt == self._rd {
            self._rd = self.src.read(&mut self._buf).unwrap_or(0);
            self._pt = (self._rd == 0) as usize;
        }
    }

    // returns true if end of file
    fn eof(&mut self) -> bool {
        self._check_buf();
        self._rd == 0
    }

    // filters \r, returns \0 if eof
    fn byte(&mut self) -> u8 {
        loop {
            self._check_buf();
            if self._rd == 0 { return 0; }
            let res = self._buf[self._pt];
            self._pt += 1;
            if res != b'\r' { return res; }
        }
    }

    fn char(&mut self) -> char { self.byte() as char }
    fn bytes_no_skip(&mut self, n: usize) -> Vec<u8> { (0..n).map(|_| self.byte()).collect() }
    fn bytes(&mut self, n: usize) -> Vec<u8> {
        let res = self.bytes_no_skip(n);
        self.byte();
        res
    }
    fn bytes2(&mut self, n: usize, m: usize) -> Vec<Vec<u8>> { (0..n).map(|_| self.bytes(m)).collect() }

    fn token_bytes(&mut self) -> Vec<u8> {
        let mut res = Vec::new();
        let mut c = self.byte();
        while c <= b' ' {
            if c == b'\0' { return res; }
            c = self.byte();
        }
        loop {
            res.push(c);
            c = self.byte();
            if c <= b' ' { return res; }
        }
    }
    fn token(&mut self) -> String { unsafe { String::from_utf8_unchecked(self.token_bytes()) } }

    fn line_bytes(&mut self) -> Vec<u8> {
        let mut res = Vec::new();
        let mut c = self.byte();
        while c != b'\n' && c != b'\0' {
            res.push(c);
            c = self.byte();
        }
        res
    }
    fn line(&mut self) -> String { unsafe { String::from_utf8_unchecked(self.line_bytes()) } }

    fn read<T: FromStr>(&mut self) -> T {
        let token = self.token_bytes();
        unsafe { from_utf8_unchecked(&token).parse::<T>().ok().unwrap()  }
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.read()).collect() }
    fn vec2<T: FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> { (0..n).map(|_| self.vec(m)).collect() }
}

trait ToCharVec { fn to_char_vec(&self) -> Vec<char>; }
impl ToCharVec for &str { fn to_char_vec(&self) -> Vec<char> { self.chars().collect() } }
impl ToCharVec for String { fn to_char_vec(&self) -> Vec<char> { self.chars().collect() } }
trait JoinToStr {
    fn join_to_str(&mut self, sep: &str) -> String;
    fn concat_to_str(&mut self) -> String;
}
impl<T: ToString, I: Iterator<Item = T>> JoinToStr for I {
    fn join_to_str(&mut self, sep: &str) -> String {
        let mut res = String::new();
        match self.next() {
            None => res,
            Some(first) => {
                res.push_str(&first.to_string());
                loop {
                    match self.next() {
                        None => break,
                        Some(item) => {
                            res.push_str(sep);
                            res.push_str(&item.to_string())
                        }
                    }
                }
                res
            }
        }
    }

    fn concat_to_str(&mut self) -> String {
        let mut res = String::new();
        for item in self { res.push_str(&item.to_string()); }
        res
    }
}

macro_rules! veci {
    ($n:expr , $i:ident : $gen:expr) => {{
        let n = $n;
        let mut list = Vec::with_capacity(n);
        for $i in 0..n {
            list.push($gen);
        }
        list
    }};
    ($n:expr , $gen:expr) => { veci!($n, __: $gen); }
}

fn abs_diff<T: Sub<Output = T> + PartialOrd>(x: T, y: T) -> T {
    if x < y { y - x } else { x - y }
}

// * end commons * //

mod modint {

    use std::{convert::Infallible, iter::Sum, mem::swap, ops::AddAssign};

    pub trait RemEuclidU32: Copy {
        /// Calculates `self` _mod_ `modulus` losslessly.
        fn rem_euclid_u32(self, modulus: u32) -> u32;

        fn pow_mod(self, exponent: u64, modulus: u32) -> u32 {
            pow_mod_raw(self.rem_euclid_u32(modulus), exponent, modulus)
        }
        fn mul_mod<Rhs: RemEuclidU32>(self, rhs: Rhs, modulus: u32) -> u32 {
            mul_mod_u32(self.rem_euclid_u32(modulus), rhs.rem_euclid_u32(modulus), modulus)
        }

        fn mod_pow_vec(self, n: usize, modulus: u32) -> Vec<u32> {
            let a = self.rem_euclid_u32(modulus);
            let mut res = vec![0u32; n+1];
            if modulus == 1 { return res; }
            res[0] = 1;
            for i in 1..=n {
                res[i] = mul_mod_u32(a, res[i-1], modulus);
            }
            res
        }
    }

    macro_rules! impl_rem_euclid_u32_for_small_signed {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        (self as i64).rem_euclid(i64::from(modulus)) as _
                    }
                }
            )*
        }
    }

    impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);

    impl RemEuclidU32 for i128 {
        #[inline]
        fn rem_euclid_u32(self, modulus: u32) -> u32 {
            self.rem_euclid(i128::from(modulus)) as _
        }
    }

    macro_rules! impl_rem_euclid_u32_for_small_unsigned {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        self as u32 % modulus
                    }
                }
            )*
        }
    }

    macro_rules! impl_rem_euclid_u32_for_large_unsigned {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        (self % (modulus as $ty)) as _
                    }
                }
            )*
        }
    }

    impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);
    impl_rem_euclid_u32_for_large_unsigned!(u64, u128);

    #[cfg(target_pointer_width = "32")]
    impl_rem_euclid_u32_for_small_unsigned!(usize);

    #[cfg(target_pointer_width = "64")]
    impl_rem_euclid_u32_for_large_unsigned!(usize);
    #[inline]
    pub fn mul_mod_u32(a: u32, b: u32, m: u32) -> u32 {
        ((a as u64) * (b as u64) % (m as u64)) as u32
    }

    #[inline]
    fn norm(a: u32, m: u32) -> u32 {
        (((a as i32) >> 31) as u32 & m) + a
    }
    // for a, b < m < 2^31, undefined otherwise
    #[inline]
    pub fn add_mod_raw(a: u32, b: u32, m: u32) -> u32 {
        sub_mod_raw(a, m-b, m)
        //norm(a.wrapping_add(b).wrapping_sub(m), m)
    }
    #[inline]
    pub fn sub_mod_raw(a: u32, b: u32, m: u32) -> u32 {
        let (r, c) = a.overflowing_sub(b);
        if c { r + m } else { r }
        //norm(a.wrapping_sub(b), m)
    }
    pub fn pow_mod_raw(a: u32, mut k: u64, m: u32) -> u32 {
        if m == 1 { return 0; }
        let mut a= a as u64;
        let m = m as u64;
        let mut r: u64 = 1;
        while k > 0 {
            if k & 1 == 1 {
                r = r * a % m;
            }
            k >>= 1;
            a = a * a % m;
        }
        return r as u32;
    }

    /// # Parameters
    /// * `b` `1 <= b`
    /// # Returns
    /// (x, g) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
    pub fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
        let a = a.rem_euclid(b);
        if a == 0 { return (0, b); }
        let mut s = b;
        let mut t = a;
        let mut m0 = 0;
        let mut m1 = 1;

        while t != 0 {
            let u = s / t;
            s -= t * u;
            m0 -= m1 * u;
            std::mem::swap(&mut s, &mut t);
            std::mem::swap(&mut m0, &mut m1);
        }

        if m0 < 0 { m0 += b / s; }
        (m0, s)
    }

    #[derive(Clone, Copy, PartialEq, Eq, Hash, Default)]
    #[repr(transparent)]
    pub struct ModInt { pub val: u32 }

    impl ModInt {
        #[inline(always)]
        pub fn modulus() -> u32 { crate::get_modulus() }
        pub fn new<I: RemEuclidU32>(val: I) -> Self { Self::raw(val.rem_euclid_u32(Self::modulus())) }
        #[inline]
        pub fn raw(val: u32) -> Self { Self { val } }
        pub fn inv(self) -> Self {
            let (x, gcd) = inv_gcd(self.val.into(), Self::modulus().into());
            if gcd != 1 { panic!("the multiplicative inverse {}^-1 mod {} does not exist", self.val, Self::modulus()) }
            Self::raw(x as u32)
        }
        pub fn pow(self, k: u64) -> Self {
            Self::raw(pow_mod_raw(self.val, k, Self::modulus()))
        }
        pub fn pow_vec(self, n: usize) -> Vec<Self> {
            let mut res = vec![Self::raw(0); n+1];
            res[0] += 1;
            for i in 1..=n {
                res[i] = res[i-1] * self;
            }
            res
        }
    }

    #[inline]
    pub fn mi<I: RemEuclidU32>(val: I) -> ModInt { ModInt::new(val) }

    impl<V: RemEuclidU32> From<V> for ModInt {
        #[inline]
        fn from(from: V) -> Self { Self::new(from) }
    }
    impl std::str::FromStr for ModInt {
        type Err = std::convert::Infallible;
        #[inline]
        fn from_str(s: &str) -> Result<Self, Self::Err> {
            Ok(s.parse::<i64>()
            .map(Self::new)
            .unwrap_or_else(|_| todo!("parsing as an arbitrary precision integer?")))
        }
    }
    impl std::fmt::Display for ModInt {
        #[inline]
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            std::fmt::Display::fmt(&self.val, f)
        }
    }
    impl std::fmt::Debug for ModInt {
        #[inline]
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            std::fmt::Debug::fmt(&self.val, f)
        }
    }
    impl std::ops::Neg for ModInt {
        type Output = ModInt;

        #[inline]
        fn neg(self) -> Self::Output {
            Self::raw(0) - self
            //Self::raw(norm(self.val.wrapping_neg(), Self::modulus()))
        }
    }

    impl std::ops::Add for ModInt {
        type Output = ModInt;
        #[inline]
        fn add(self, rhs: Self) -> Self::Output {
            Self::raw(add_mod_raw(self.val, rhs.val, Self::modulus()))
        }
    }
    impl std::ops::Sub for ModInt {
        type Output = ModInt;
        #[inline]
        fn sub(self, rhs: Self) -> Self::Output {
            Self::raw(sub_mod_raw(self.val, rhs.val, Self::modulus()))
        }
    }
    impl std::ops::Mul for ModInt {
        type Output = ModInt;
        #[inline]
        fn mul(self, rhs: Self) -> Self::Output {
            Self::raw(mul_mod_u32(self.val, rhs.val, Self::modulus()))
        }
    }
    impl std::ops::Div for ModInt {
        type Output = ModInt;
        #[inline]
        fn div(self, rhs: Self) -> Self::Output { self * rhs.inv() }
    }

    impl <I: RemEuclidU32> std::ops::Add<I> for ModInt {
        type Output = ModInt;
        #[inline]
        fn add(self, rhs: I) -> Self::Output { self + Self::new(rhs) }
    }
    impl <I: RemEuclidU32> std::ops::Sub<I> for ModInt {
        type Output = ModInt;
        #[inline]
        fn sub(self, rhs: I) -> Self::Output { self - Self::new(rhs) }
    }
    impl <I: RemEuclidU32> std::ops::Mul<I> for ModInt {
        type Output = ModInt;
        #[inline]
        fn mul(self, rhs: I) -> Self::Output { self * Self::new(rhs) }
    }
    impl <I: RemEuclidU32> std::ops::Div<I> for ModInt {
        type Output = ModInt;
        #[inline]
        fn div(self, rhs: I) -> Self::Output { self / Self::new(rhs) }
    }

    impl std::ops::AddAssign for ModInt {
        #[inline]
        fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; }
    }
    impl std::ops::SubAssign for ModInt {
        #[inline]
        fn sub_assign(&mut self, rhs: Self) { *self = *self - rhs; }
    }
    impl std::ops::MulAssign for ModInt {
        #[inline]
        fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs; }
    }
    impl std::ops::DivAssign for ModInt {
        #[inline]
        fn div_assign(&mut self, rhs: Self) { *self = *self / rhs; }
    }
    impl <I: RemEuclidU32> std::ops::AddAssign<I> for ModInt {
        #[inline]
        fn add_assign(&mut self, rhs: I) { *self = *self + rhs; }
    }
    impl <I: RemEuclidU32> std::ops::SubAssign<I> for ModInt {
        #[inline]
        fn sub_assign(&mut self, rhs: I) { *self = *self - rhs; }
    }
    impl <I: RemEuclidU32> std::ops::MulAssign<I> for ModInt {
        #[inline]
        fn mul_assign(&mut self, rhs: I) { *self = *self * rhs; }
    }
    impl <I: RemEuclidU32> std::ops::DivAssign<I> for ModInt {
        #[inline]
        fn div_assign(&mut self, rhs: I) { *self = *self / rhs; }
    }

    impl std::iter::Sum for ModInt {
        #[inline]
        fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(Self::raw(0), std::ops::Add::add)
        }
    }
    impl std::iter::Product for ModInt {
        #[inline]
        fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(1.into(), std::ops::Mul::mul)
        }
    }
}

// const MODULUS: u32 = 998_244_353;
// //const MODULUS: u32 = 1_000_000_007;
// #[inline(always)]
// fn get_modulus() -> u32 { MODULUS }

static mut MODULUS: u32 = 998244353;
#[inline] fn get_modulus() -> u32 { unsafe { MODULUS } }
#[inline] fn set_modulus(value: u32) { unsafe { MODULUS = value; } }

use crate::modint::*;

#[allow(non_snake_case, unused_macros)]
fn main() -> Result<(), Box<dyn Error>> {
    let mut INPUT = std::io::stdin();
    let OUTPUT = std::io::stdout();

    let mut inp = Scanner::new(&mut INPUT);
    let mut out = BufWriter::with_capacity(IO_BUF_SIZE, OUTPUT);

    macro_rules! inp {
        () => { inp.read(); };
        ($t: ty) => { inp.read::<$t>(); };
        ($t: ty, $($tt: ty),*) => { (inp.read::<$t>(), $(inp.read::<$tt>(),)*); };
        [$t: ty; $n: expr] => { inp.vec::<$t>($n); };
    }
    macro_rules! println {
        () => { writeln!(out).unwrap(); };
        ($exp: expr) => { writeln!(out, "{}", $exp).unwrap(); };
        ($fmt: expr, $($arg : tt )*) => { writeln!(out, $fmt, $($arg)*).unwrap(); }
    }
    macro_rules! print {
        ($exp: expr) => { write!(out, "{}", $exp).unwrap(); };
        ($fmt: expr, $($arg : tt )*) => { write!(out, $fmt, $($arg)*).unwrap(); }
    }

    { // solution start
        let num_cases = 1;//inp!(usize);

        for _case_num in 1..=num_cases {
            let n = inp!(usize);
            set_modulus(inp!());

            let mut dp = vec![mi(0); n+1];
            dp[1] = mi(1);
            dp[2] = mi(2);
            for i in 2..n {
                let d = dp[i];
                dp[i+1] += d + d + 1;
                let d = d - dp[i-1];
                for j in (i*2..=n).step_by(i) {
                    dp[j] += d;
                }
            }

            let ans = dp[n];
            println!(ans);
        }
    } // solution end

    out.flush()?;
    Ok(())
}


#![allow(unused_imports)]
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

fn main() {
    let mut first = String::new();
    let mut second = String::new();
    io::stdin().read_line(&mut first).unwrap();
    io::stdin().read_line(&mut second).unwrap();
    let fir: Vec<char> = first.chars().filter(|c| c.is_digit(2)).collect();
    let sec: Vec<char> = second.chars().filter(|c| c.is_digit(2)).collect();
    let mut out = vec!['_'; fir.len()];

    for i in 0..fir.len() {
        if fir[i] == sec[i] {
            out[i] = '0';
        } else {
            out[i] = '1';
        }
    }

    println!("{}", out.iter().collect::<String>());
}


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

fn main() {
    let stdin = io::stdin();
    let mut iterator = stdin.lock().lines();
    let first = iterator.next().unwrap().unwrap();
    let second = iterator.next().unwrap().unwrap();

    let first_vec: Vec<char> = first.chars().collect();
    let second_vec: Vec<char> = second.chars().collect();

    let mut result = Vec::new();

    for i in 0..first_vec.len() {
        if first_vec[i] != second_vec[i] {
            result.push("1");
        } else {
            result.push("0");
        }
    }

    println!("{}", result.join(""));
}


use std::io;
use std::str::SplitWhitespace;

fn main() {
    let mut input: String = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut it_input: SplitWhitespace = input.split_whitespace();
    let n: i32 = it_input.next().unwrap().parse().unwrap();
    let m: i32 = it_input.next().unwrap().parse().unwrap();
    let r: i32 = it_input.next().unwrap().parse().unwrap();
    let mut n_input: String = String::new();
    let mut m_input: String = String::new();
    io::stdin().read_line(&mut n_input).unwrap();
    io::stdin().read_line(&mut m_input).unwrap();
    let mut it_n: SplitWhitespace = n_input.split_whitespace();
    let mut it_m: SplitWhitespace = m_input.split_whitespace();
    let mut n_min: i32 = 1001;
    let mut m_max: i32 = 0;
    for _i in 0..n {
        let a: i32 = it_n.next().unwrap().parse().unwrap();
        if a < n_min {
            n_min = a;
        }
    }
    for _i in 0..m {
        let a: i32 = it_m.next().unwrap().parse().unwrap();
        if a > m_max {
            m_max = a;
        }
    }
    if r / n_min * m_max + r % n_min > r {
        print!("{}", r / n_min * m_max + r % n_min);
    } else {
        print!("{}", r);
    }
}


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 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 m: usize = scan.next();
    let r: usize = scan.next();
    let buy: usize = scan.next_n::<usize>(n).into_iter().min().unwrap();
    let sell: usize = scan.next_n::<usize>(m).into_iter().max().unwrap();
    println!(
        "{}",
        if buy >= sell {
            r
        } else {
            r % buy + r / buy * sell
        }
    );
}

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


// ---------- begin ModInt ----------
mod modint {

    #[allow(dead_code)]
    pub struct Mod;
    impl ConstantModulo for Mod {
        const MOD: u32 = 1_000_000_007;
    }

    #[allow(dead_code)]
    pub struct StaticMod;
    static mut STATIC_MOD: u32 = 0;
    impl Modulo for StaticMod {
        fn modulo() -> u32 {
            unsafe { STATIC_MOD }
        }
    }

    #[allow(dead_code)]
    impl StaticMod {
        pub fn set_modulo(p: u32) {
            unsafe {
                STATIC_MOD = p;
            }
        }
    }

    use std::marker::*;
    use std::ops::*;

    pub trait Modulo {
        fn modulo() -> u32;
    }

    pub trait ConstantModulo {
        const MOD: u32;
    }

    impl<T> Modulo for T
    where
        T: ConstantModulo,
    {
        fn modulo() -> u32 {
            T::MOD
        }
    }

    pub struct ModInt<T>(pub u32, PhantomData<T>);

    impl<T> Clone for ModInt<T> {
        fn clone(&self) -> Self {
            ModInt::new_unchecked(self.0)
        }
    }

    impl<T> Copy for ModInt<T> {}

    impl<T: Modulo> Add for ModInt<T> {
        type Output = ModInt<T>;
        fn add(self, rhs: Self) -> Self::Output {
            let mut d = self.0 + rhs.0;
            if d >= T::modulo() {
                d -= T::modulo();
            }
            ModInt::new_unchecked(d)
        }
    }

    impl<T: Modulo> AddAssign for ModInt<T> {
        fn add_assign(&mut self, rhs: Self) {
            *self = *self + rhs;
        }
    }

    impl<T: Modulo> Sub for ModInt<T> {
        type Output = ModInt<T>;
        fn sub(self, rhs: Self) -> Self::Output {
            let mut d = T::modulo() + self.0 - rhs.0;
            if d >= T::modulo() {
                d -= T::modulo();
            }
            ModInt::new_unchecked(d)
        }
    }

    impl<T: Modulo> SubAssign for ModInt<T> {
        fn sub_assign(&mut self, rhs: Self) {
            *self = *self - rhs;
        }
    }

    impl<T: Modulo> Mul for ModInt<T> {
        type Output = ModInt<T>;
        fn mul(self, rhs: Self) -> Self::Output {
            let v = self.0 as u64 * rhs.0 as u64 % T::modulo() as u64;
            ModInt::new_unchecked(v as u32)
        }
    }

    impl<T: Modulo> MulAssign for ModInt<T> {
        fn mul_assign(&mut self, rhs: Self) {
            *self = *self * rhs;
        }
    }

    impl<T: Modulo> Neg for ModInt<T> {
        type Output = ModInt<T>;
        fn neg(self) -> Self::Output {
            if self.0 == 0 {
                Self::zero()
            } else {
                Self::new_unchecked(T::modulo() - self.0)
            }
        }
    }

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

    impl<T: Modulo> std::str::FromStr for ModInt<T> {
        type Err = std::num::ParseIntError;
        fn from_str(s: &str) -> Result<Self, Self::Err> {
            let val = s.parse::<u32>()?;
            Ok(ModInt::new(val))
        }
    }

    impl<T: Modulo> From<usize> for ModInt<T> {
        fn from(val: usize) -> ModInt<T> {
            ModInt::new_unchecked((val % T::modulo() as usize) as u32)
        }
    }

    impl<T: Modulo> From<u64> for ModInt<T> {
        fn from(val: u64) -> ModInt<T> {
            ModInt::new_unchecked((val % T::modulo() as u64) as u32)
        }
    }

    impl<T: Modulo> From<i64> for ModInt<T> {
        fn from(val: i64) -> ModInt<T> {
            let m = T::modulo() as i64;
            ModInt::new((val % m + m) as u32)
        }
    }

    #[allow(dead_code)]
    impl<T> ModInt<T> {
        pub fn new_unchecked(d: u32) -> Self {
            ModInt(d, PhantomData)
        }
        pub fn zero() -> Self {
            ModInt::new_unchecked(0)
        }
        pub fn one() -> Self {
            ModInt::new_unchecked(1)
        }
        pub fn is_zero(&self) -> bool {
            self.0 == 0
        }
    }

    #[allow(dead_code)]
    impl<T: Modulo> ModInt<T> {
        pub fn new(d: u32) -> Self {
            ModInt::new_unchecked(d % T::modulo())
        }
        pub fn pow(&self, mut n: u64) -> Self {
            let mut t = Self::one();
            let mut s = *self;
            while n > 0 {
                if n & 1 == 1 {
                    t *= s;
                }
                s *= s;
                n >>= 1;
            }
            t
        }
        pub fn inv(&self) -> Self {
            assert!(self.0 != 0);
            self.pow(T::modulo() as u64 - 2)
        }
    }

    #[allow(dead_code)]
    pub fn mod_pow(r: u64, mut n: u64, m: u64) -> u64 {
        let mut t = 1 % m;
        let mut s = r % m;
        while n > 0 {
            if n & 1 == 1 {
                t = t * s % m;
            }
            s = s * s % m;
            n >>= 1;
        }
        t
    }
}
// ---------- end ModInt ----------
// ---------- begin Precalc ----------
mod precalc {
    use super::modint::*;
    #[allow(dead_code)]
    pub struct Precalc<T> {
        inv: Vec<ModInt<T>>,
        fact: Vec<ModInt<T>>,
        ifact: Vec<ModInt<T>>,
    }
    #[allow(dead_code)]
    impl<T: Modulo> Precalc<T> {
        pub fn new(n: usize) -> Precalc<T> {
            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) {
                fact[i] = fact[i - 1] * ModInt::new_unchecked(i as u32);
            }
            ifact[n] = fact[n].inv();
            if n > 0 {
                inv[n] = ifact[n] * fact[n - 1];
            }
            for i in (1..n).rev() {
                ifact[i] = ifact[i + 1] * ModInt::new_unchecked((i + 1) as u32);
                inv[i] = ifact[i] * fact[i - 1];
            }
            Precalc {
                inv: inv,
                fact: fact,
                ifact: ifact,
            }
        }
        pub fn inv(&self, n: usize) -> ModInt<T> {
            assert!(n > 0);
            self.inv[n]
        }
        pub fn fact(&self, n: usize) -> ModInt<T> {
            self.fact[n]
        }
        pub fn ifact(&self, n: usize) -> ModInt<T> {
            self.ifact[n]
        }
        pub fn perm(&self, n: usize, k: usize) -> ModInt<T> {
            if k > n {
                return ModInt::zero();
            }
            self.fact[n] * self.ifact[n - k]
        }
        pub fn comb(&self, n: usize, k: usize) -> ModInt<T> {
            if k > n {
                return ModInt::zero();
            }
            self.fact[n] * self.ifact[k] * self.ifact[n - k]
        }
    }
}
// ---------- end Precalc ----------
//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")
    };
}

//

use modint::*;
use precalc::*;

type M = ModInt<Mod>;

fn run() {
    input! {
        p: u64,
        k: u64,
    }
    let ans = if k == 0 {
        M::from(p).pow(p - 1)
    } else if k == 1 {
        M::from(p).pow(p)
    } else {
        let mut phi = p - 1;
        let mut m = phi;
        for d in 2.. {
            if d * d > m {
                break;
            }
            if m % d == 0 {
                while m % d == 0 {
                    m /= d;
                }
                while phi % d == 0 && mod_pow(k, phi / d, p) == 1 {
                    phi /= d;
                }
            }
        }
        if m > 1 && mod_pow(k, phi / m, p) == 1 {
            phi /= m;
        }
        M::from(p).pow((p - 1) / phi)
    };
    println!("{}", ans);
}

fn main() {
    run();
}