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

fn factorial(x: i32) -> i32 {
    if x < 2 {
        return 1;
    } else {
        return x * factorial(x - 1);
    }
}

fn main() {
    let reader = io::stdin();
    let numbers: Vec<i32> =
        reader.lock()                           // (0)
            .lines().next().unwrap().unwrap() // (1)
            .split(' ').map(|s| s.trim())     // (2)
            .filter(|s| !s.is_empty())        // (3)
            .map(|s| s.parse().unwrap())      // (4)
            .collect();                       // (5)

    let mut min= numbers[0];
    if numbers[1] < min {
        min = numbers[1];
    }

    println!("{}", factorial(min));
}


#[allow(unused_imports)]
use std::io;
use std::cmp::{min, max};
use std::mem;
use std::str::FromStr;
use std::cmp::Ordering;
use std::collections::BinaryHeap;

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

impl<B: io::BufRead> Scanner<B> {
    pub fn new(reader: B) -> Scanner<B> {
        Scanner {
            reader: reader,
            buffer: Vec::new(),
        }
    }

    /// Use "turbofish" syntax next::<T>() to select data type of next token.
    pub fn next<T: ::std::str::FromStr>(&mut self) -> T
        where
            T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }

    pub fn next_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            T::Err: ::std::fmt::Debug,
    {
        (0..len).map(|_| self.next::<T>()).collect::<Vec<T>>()
    }
}

fn main1() {
    let stdin = io::stdin();
    let mut input = Scanner::new(stdin.lock());
    let a: i64 = input.next();
    let b: i64 = input.next();
    let n = min(a, b);
    let answer = (1..(n + 1)).fold(1i64, |mul, x| mul * x);
    println!("{}", answer);

}

fn main() {
    std::thread::Builder::new().stack_size(50 << 20)
        .spawn(main1).unwrap().join().unwrap();
}


use std::io;
use std::str::{FromStr, SplitWhitespace};
use std::fmt::Debug;
use std::iter::Map;
use std::cmp::min;

fn main() {
    let (a,b) = Input::line().pair();
    let res = (1..min::<u64>(a,b) + 1).fold(1, |ref x, i| x * i) ;
    println!("{}", res);

}

pub trait UParse: FromStr {
    fn uparse(&str) -> Self;
}
impl<T> UParse for T
where
    T: FromStr,
    T::Err: Debug,
{
    fn uparse(str: &str) -> Self {
        str.trim().parse().unwrap()
    }
}

pub struct Input(String);
impl Input {
    pub fn line() -> Input {
        let mut str = String::new();
        io::stdin().read_line(&mut str).unwrap();
        Input(str)
    }

    fn trim_parse<T: UParse>(s: &str) -> T {
        UParse::uparse(s)
    }

    pub fn iter<T: UParse>(&self) -> Map<SplitWhitespace, fn(&str) -> T> {
        self.0.split_whitespace().map(Input::trim_parse)
    }

    pub fn single<T: UParse>(&self) -> T {
        Input::trim_parse(self.0.as_ref())
    }

    pub fn pair<A: UParse, B: UParse>(&self) -> (A, B) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        (a, b)
    }

    pub fn triple<A: UParse, B: UParse, C: UParse>(&self) -> (A, B, C) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        (a, b, c)
    }

    pub fn quadruple<A: UParse, B: UParse, C: UParse, D: UParse>(&self) -> (A, B, C, D) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        let d = Input::trim_parse(it.next().unwrap());
        (a, b, c, d)
    }
}


use std::io::stdin;

fn read_n() -> (u32, u32) {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer).unwrap();
    let snums: Vec<&str> = buffer.trim().split(" ").collect();
    (snums[0].parse::<u32>().unwrap(), snums[1].parse::<u32>().unwrap())
}

fn factorial(x: u32) -> u32 {
    let mut n: u32 = 1;
    for i in 2..x+1 {
        n *= i;
    }
    n
}

fn main() {
    let (a, b) = read_n();
    if a < b {
        println!("{}", factorial(a));
    } else {
        println!("{}", factorial(b));
    }
}


use std::io;
use std::str::{FromStr, SplitWhitespace};
use std::fmt::Debug;
use std::iter::Map;
use std::cmp::min;

fn main() {
    let (a,b) = Input::line().pair();
    let res = (1..min::<u32>(a,b) + 1).fold(1, |ref x, i| x * i) ;
    println!("{}", res);

}

pub trait UParse: FromStr {
    fn uparse(&str) -> Self;
}
impl<T> UParse for T
where
    T: FromStr,
    T::Err: Debug,
{
    fn uparse(str: &str) -> Self {
        str.trim().parse().unwrap()
    }
}

pub struct Input(String);
impl Input {
    pub fn line() -> Input {
        let mut str = String::new();
        io::stdin().read_line(&mut str).unwrap();
        Input(str)
    }

    fn trim_parse<T: UParse>(s: &str) -> T {
        UParse::uparse(s)
    }

    pub fn iter<T: UParse>(&self) -> Map<SplitWhitespace, fn(&str) -> T> {
        self.0.split_whitespace().map(Input::trim_parse)
    }

    pub fn single<T: UParse>(&self) -> T {
        Input::trim_parse(self.0.as_ref())
    }

    pub fn pair<A: UParse, B: UParse>(&self) -> (A, B) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        (a, b)
    }

    pub fn triple<A: UParse, B: UParse, C: UParse>(&self) -> (A, B, C) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        (a, b, c)
    }

    pub fn quadruple<A: UParse, B: UParse, C: UParse, D: UParse>(&self) -> (A, B, C, D) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        let d = Input::trim_parse(it.next().unwrap());
        (a, b, c, d)
    }
}


fn factorial(n: i32) -> i32 {
    if n == 0 {
        1
    } else {
        n * factorial(n - 1)
    }
}

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

fn main() {
    let mut input = String::new();

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

    let mut iter = input.split_whitespace().map(|p| p.parse::<i32>().unwrap());

    let a = iter.next().unwrap();
    let b = iter.next().unwrap();

    let c = cmp::min(a, b);
    println!("{}", factorial(c));
}


fn fact(n: u32) -> u32 {
    if n == 1 {
        1
    } else {
        n * fact(n - 1)
    }
}

fn main() {
    let (a, b) = {
        let mut buf = String::with_capacity(3);
        std::io::stdin().read_line(&mut buf).unwrap();
        let nums: Vec<u32> = buf
            .trim()
            .split_whitespace()
            .map(|a| a.parse().unwrap())
            .collect();
        (nums[0], nums[1])
    };

    print!("{}", fact(a.min(b)));
}


fn factorial(x: usize) -> usize {
    let mut result: usize = 1;
    for i in 1..=x {
        result *= i;
    }
    result
}

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();
    println!("{}", factorial(a.min(b)));
}

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


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn prime_factorization(mut n: u64) -> Vec<(u64, u64)> {
    let mut i = 2;
    let mut ans = vec![];
    while i*i <= n {
        let mut cnt = 0;
        while n%i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            ans.push((i, cnt));
        }
        i += 1;
    }
    if n > 1 {
        ans.push((n, 1));
    }
    ans
}

fn fact_num(n: u64, v: u64) -> u64 {
    if n < v {
        return 0;
    }
    let div = n/v;
    div + fact_num(div, v)
}

fn main() {
    input!{
      n: u64,
      b: u64,
    }
    let facts = prime_factorization(b);
    let mut ans: i64 = -1;
    for i in 0..facts.len() {
        let (v, pow) = facts[i];
        let fnum = fact_num(n, v);
        if ans == -1 {
            ans = (fnum/pow) as i64;
        } else {
            ans = min(ans, (fnum/pow) as i64);
        }
    }
    println!("{}", ans);
}


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

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

    l!(n,b: i64 = input.p());
    let mut sol = n;
    let mut b = b;
    let mut i = 2;
    while b > 1 {
        if i * i > b {
            i = b;
        }
        if b % i == 0 {
            let mut c = 0;
            while b % i == 0 {
                b /= i;
                c += 1;
            }
            let mut a = n;
            let mut b = 0;
            while a > 0 {
                a /= i;
                b += a;
            }
            m!(<, sol, b/c);
        }
        i += 1;
    }
    println!("{}", sol);
}


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

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

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

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

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

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

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

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

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

mod pollard_rho {
    use std::collections::HashMap;
    /// binary gcd
    pub fn gcd(mut x: i64, mut y: i64) -> i64 {
        if y == 0 { return x; }
        if x == 0 { return y; }
        let mut sh = 0;
        while ((x | y) & 1) == 0 {
            x >>= 1; y >>= 1; sh += 1;
        }
        while (x & 1) == 0 { x >>= 1; }
        while y != 0 {
            while (y & 1) == 0 { y >>= 1; }
            if x > y { let t = x; x = y; y = t; }
            y -= x;
        }
        x << sh
    }

    fn add_mod(x: i64, y: i64, n: i64) -> i64 {
        let z = x + y;
        if z >= n { z - n } else { z }
    }

    fn mul_mod(x: i64, mut y: i64, n: i64) -> i64 {
        assert!(x >= 0);
        assert!(x < n);
        let mut sum = 0;
        let mut cur = x;
        while y > 0 {
            if (y & 1) == 1 {
                sum = add_mod(sum, cur, n);
            }
            cur = add_mod(cur, cur, n);
            y >>= 1;
        }
        sum
    }

    fn mod_pow(x: i64, mut e: i64, n: i64) -> i64 {
        let mut prod = if n == 1 { 0 } else { 1 };
        let mut cur = x % n;
        while e > 0 {
            if (e & 1) == 1 {
                prod = mul_mod(prod, cur, n);
            }
            cur = mul_mod(cur, cur, n);
            e >>= 1;
        }
        prod
    }

    pub fn is_prime(n: i64) -> bool {
        if n <= 1 { return false; }
        let small = [2, 3, 5, 7, 11, 13];
        if small.iter().any(|&u| u == n) { return true; }
        if small.iter().any(|&u| n % u == 0) { return false; }
        let mut d = n - 1;
        let mut e = 0;
        while (d & 1) == 0 {
            d >>= 1;
            e += 1;
        }
        let a = [2, 325, 9375, 28178, 450775, 9780504, 1795265022];
        a.iter().all(|&a| {
            if a >= n { return true; }
            let mut x = mod_pow(a, d, n);
            if x == 1 { return true; }
            for _ in 0 .. e {
                if x == n - 1 {
                    return true;
                }
                x = mul_mod(x, x, n);
                if x == 1 { return false; }
            }
            x == 1
        })
    }

    fn pollard_rho(n: i64, c: &mut i64) -> i64 {
        if n % 2 == 0 { return 2; }
        loop {
            let mut x: i64 = 2;
            let mut y = 2;
            let mut d = 1;
            let cc = *c;
            let f = |i| add_mod(mul_mod(i, i, n), cc, n);
            while d == 1 {
                x = f(x);
                y = f(f(y));
                d = gcd((x - y).abs(), n);
            }
            if d == n {
                *c += 1;
                continue;
            }
            return d;
        }
    }

    /// Outputs (p, e) in p's ascending order.
    pub fn factorize(x: i64) -> Vec<(i64, usize)> {
        if x <= 1 {
            return Vec::new();
        }
        let mut hm = HashMap::new();
        let mut pool = vec![x];
        let mut c = 1;
        while let Some(u) = pool.pop() {
            if is_prime(u) {
                *hm.entry(u).or_insert(0) += 1;
                continue;
            }
            let p = pollard_rho(u, &mut c);
            pool.push(p);
            pool.push(u / p);
        }
        let mut v: Vec<_> = hm.into_iter().collect();
        v.sort();
        v
    }
} // mod pollard_rho

use pollard_rho::*;

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i64,
        b: i64,
    }
    let fac = factorize(b);
    let mut mi: i64 = 1 << 62;
    for (p, e) in fac {
        let mut tot = 0;
        let mut v = n;
        while v > 0 {
            v /= p;
            tot += v;
        }
        mi = min(mi, tot / e as i64);
    }
    puts!("{}\n", mi);
}

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


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

fn main() {
    let tmp = readline_ints();
    let n = tmp[0];
    let b = tmp[1];

    let fs = factor(b);
    let mut ans = std::i64::MAX;

    // println!("{:?}", fs);

    for &(p, cnt) in fs.iter() {
        //println!("{}", count(n, p) / cnt);
        ans = min(count(n, p) / cnt, ans);
    }

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

fn factor(mut n: i64) -> Vec<(i64, i64)> {
    let mut fs: Vec<(i64, i64)> = Vec::new();
    for i in 2..((n as f64).sqrt().ceil() as i64 + 1) {
        let mut cnt = 0i64;
        while n % i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            fs.push((i as i64, cnt));
        }
    }
    if n > 1 {
        fs.push((n, 1));
    }
    fs
}

fn count(n: i64, p: i64) -> i64 {
    let mut c = 0i64;
    let mut b = p;
    while n >= b {
        c += n / b;
        //println!("n = {}, b = {}, n/b = {}", n, b, n/b);

        if n/b >= p {
            b *= p;
        } else {
            break;
        }
    }
    c
}

fn readline_ints() -> Vec<i64> {
    let mut strs = String::new();
    let _ = io::stdin().read_line(&mut strs);
    strs.split_whitespace().map(|s| s.parse::<i64>().unwrap()).collect()
}


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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: i64 = util::get();
    let n_digits = (1..).find(|&d| 10i64.pow(d as u32) > n).unwrap();

    let ans: Vec<i64> = (max(0, n - n_digits * 9)..n + 1)
        .filter(|&x| {
            let mut a = x;
            let mut y = x;

            while y > 0 {
                a += y % 10;
                y /= 10;
            }

            a == n
        })
        .collect();

    if ans.is_empty() {
        println!("0");
    } else {
        println!("{}", ans.len());
        for &x in &ans {
            println!("{}", x);
        }
    }
}


use std::io::{stdin, BufRead, BufReader};
use std::vec::Vec;
use std::process;

const MAX_DIFF: i32 = 90;

fn digit_sum(n: i32) -> i32 {
    let mut result = 0;
    let mut t = n;
    while t > 0 {
        result = result + (t % 10);
        t = t / 10;
    }
    result
}

fn solve(n: i32) -> Vec<i32> {
    let mut result: Vec<i32> = Vec::new();
    for x in 1..MAX_DIFF {
        let t = n - x;
        if digit_sum(t) == x {
            result.push(t);
        }
    }
    result
}

#[allow(non_snake_case)]
#[allow(unused_variables)]
fn main() {
    let mut reader = BufReader::new(stdin());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let N = s.trim_right().parse::<i32>().unwrap();
    let mut solved = solve(N);
    let mut result = solved.as_mut_slice();
    result.sort();
    println!("{}", result.len());
    if result.len() == 0 {
        process::exit(0);
    }
    s.clear();
    for i in 0..result.len() {
        s.push_str(result[i].to_string().as_str());
        if i != result.len() - 1 {
            s.push(' ');
        }
    }
    println!("{}", s);
}


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

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

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

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

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let n: u32 = get_line().trim().parse().unwrap();

    // La somme est inférieure à 81.
    // n <= x + 81
    // n - 81 <= x <= n

    let min_ind = if n > 81 {
        n - 81
    } else {
        0
    };

    let digit_sum = |x| {
        let s = format!("{}", x);
        s.bytes().map(|b| (b - b'0') as u32).sum::<u32>()
    };

    let answers: Vec<_> = (min_ind..n + 1).filter(|&i| i + digit_sum(i) == n).collect();

    println!("{}", answers.len());
    for ans in answers {
        println!("{}", ans);
    }
}


use std::io::stdin;
use std::io::prelude::*;
use std::iter::*;
use std::str::SplitWhitespace;
use std::cmp::max;

fn main() {
    let mut input = InRead::new();
    let n = input.int();
    let mut sols = Vec::new();
    for i in max(n - 90, 1)..n {
        if i + sumdigits(i) == n { sols.push(i.to_string()) };
    }
    println!("{}\n{}", sols.len(), sols.join(" "));
}

fn sumdigits(x: i32) -> i32 {
    if x == 0 { 0 } else { (x % 10) + sumdigits(x / 10) }
}

struct InRead(String);

impl InRead {
    fn new() -> InRead {
        InRead(String::new())
    }
    fn get_line(self: &mut Self) {
        self.0.clear();
        stdin().read_line(&mut self.0);
    }
    fn parse_int(s: &str) -> i32 { s.parse().unwrap() }
    fn ints(self: &mut Self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.get_line();
        self.0.split_whitespace().map(InRead::parse_int)
    }
    fn int_vec(self: &mut Self) -> Vec<i32> { self.ints().collect() }
    fn int(self: &mut Self) -> i32 { self.ints().next().unwrap() }
    fn int2(self: &mut Self) -> (i32, i32) {
        let mut is = self.ints();
        (is.next().unwrap(), is.next().unwrap())
    }
    fn int3(self: &mut Self) -> (i32, i32, i32) {
        let mut is = self.ints();
        (is.next().unwrap(), is.next().unwrap(), is.next().unwrap())
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

#[allow(unused_macros)]
macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let n = parse_line!(usize);
    let ok = n % 2 == 1;
    writeln!(writer, "{}", if ok {"Ehab"} else {"Mahmoud"}).unwrap();
}

fn main() {
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve(&mut writer);
    }
}


use std::io;

pub fn main() {
    let input = get_input();
    match input % 2 {
        0 => println!("Mahmoud"),
        _ => println!("Ehab"),
    };
}

fn get_input() -> u64 {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    input.trim().parse::<u64>().unwrap()
}


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

    let num: i32 = input.trim().parse().unwrap();

    if num % 2 == 0 {
        println!("Mahmoud");
    } else {
        println!("Ehab");
    }
}


use procon::*;
use std::io;
fn main() {
    try_main().unwrap();
}

fn try_main() -> Result<(), Box<std::error::Error>> {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n = sc.next::<usize>();
    if n % 2 == 0 {
        println!("Mahmoud");
    } else {
        println!("Ehab");
    }
    Ok(())
}

mod procon {
    use std::io;
    use std::cmp::Ordering;
    /// Scanner is taken from https://github.com/EbTech/rust-algorithms
    pub struct Scanner<B> {
        reader: B,
        buffer: Vec<String>,
    }

    impl<B: io::BufRead> Scanner<B> {
        pub fn new(reader: B) -> Self {
            Self {
                reader,
                buffer: Vec::new(),
            }
        }

        pub fn next<T: ::std::str::FromStr>(&mut self) -> T
            where
            T::Err: ::std::fmt::Debug,
        {
            if let Some(front) = self.buffer.pop() {
                front.parse::<T>().expect(&front)
            } else {
                let mut input = String::new();
                self.reader.read_line(&mut input).expect("Line not read");
                self.buffer = input.split_whitespace().rev().map(String::from).collect();
                self.next()
            }
        }
    }

    pub fn merge<'a, T>(this: &'a [T], that: &'a [T], out: &'a mut [T])
        where T: Ord + Copy {
        let mut i = 0;
        let mut j = 0;
        let mut oind = 0;
        while i < this.len() && j < that.len() {
            if this[i] <= that[j] {
                out[oind] = this[i];
                i += 1;
            } else {
                out[oind] = that[j];
                j += 1;
            }
            oind += 1;
        }
        while i < this.len() {
            out[oind] = this[i];
            i += 1;
            oind += 1;
        }
        while j < that.len() {
            out[oind] = that[j];
            j += 1;
            oind += 1;
        }
    }

    /// trait for implementing functions to get lower/upper bounds (implementation is based on the rust std library)
    /// the functions return OK(indx) if self[indx] is the element we queried.
    /// e.g., in lower_bound_by, f(self[indx]) returns Ordering::Equal if the function returned Ok(indx).
    /// Further, if all the elements are less than the queried value, lower_bound/upper_bound must return Err(self.len()).
    /// Similarly, all the elements are greater than the queried value, they must return Err(0).
    pub trait CmpSearch {
        type Item;

        fn find_bound_by<'a, F>(&'a self, f: F, is_lower: bool) -> Result<usize, usize>
            where F: FnMut(&'a Self::Item) -> Ordering;

        fn find_bound_by_key<'a, B, F>(&'a self, b: &B, f: F, is_lower: bool) -> Result<usize, usize>
            where F: FnMut(&'a Self::Item) -> B,
                  B: Ord;

        /// returns Result<usize, usize> which contains the lowest index indx that satisfies the following condition,
        /// assuming that self is already sorted:
        /// 1. self[i] < x if i < indx
        /// 2. self[i] >= x if i >= indx
        /// 3. self.insert(indx, x) keeps the sorted order.
        /// The return value is Ok(indx) if there is an index that satisfies x.cmp(self[indx]) == Ordering::Equal.
        /// Otherwise the return value is Err(indx).
        ///
        fn lower_bound(&self, x: &Self::Item) -> Result<usize, usize>
            where Self::Item: Ord {
            self.find_bound_by(|elem| { elem.cmp(x) }, true)
        }

        /// returns Result<usize, usize> which contains the highest index indx that satisfies the following condition,
        /// assuming that self is already sorted:
        /// 1. self[i] <= x if i <= indx
        /// 2. self[i] > x if i > indx
        /// 3. self.insert(indx, x) keeps the sorted order.
        /// The return value is Ok(indx) if there is an index that satisfies x.cmp(self[indx]) == Ordering::Equal.
        /// Otherwise the return value is Err(indx).
        ///
        fn upper_bound(&self, x: &Self::Item) -> Result<usize, usize>
            where Self::Item: Ord {
            self.find_bound_by(|elem| { elem.cmp(x) }, false)
        }
    }

    impl<T> CmpSearch for [T] {
        type Item = T;

        /// loop invariants (if is_lower = true):
        /// 1. f(self[lb]) == Less, assuming that lb >= 0
        /// 2. f(self[ub]) == Greater or Equal, assuming that gb < self.len()
        /// 3. lb < ub; in particular, lb != ub
        ///
        /// after the loop:
        /// 1. if ub < self.len(), ub is a valid index in the slice
        /// 2. if lb == -1, ub == 0 and:
        ///   2-1. f(self[0]) == Equal then the return value is Ok(0)
        ///   2-2. f(self[0]) == Greater then the return value is Err(0)
        /// 3. if ub == self.len(), lb == self.len() - 1 and the return value is Err(self.len())
        ///
        /// a similar set of conditions holds if is_lower = false.
        ///
        fn find_bound_by<'a, F>(&'a self, mut f: F, is_lower: bool) -> Result<usize, usize>
            where F: FnMut(&'a Self::Item) -> Ordering {
            let mut lb: isize = -1;
            let mut ub: isize = self.len() as isize;
            let mut step = (ub - lb) / 2;
            while step > 0 {
                let m = (lb + step) as usize;
                match f(&self[m]) {
                    Ordering::Less => {
                        lb = m as isize;
                    },
                    Ordering::Greater => {
                        ub = m as isize;
                    },
                    Ordering::Equal => {
                        if is_lower {
                            ub = m as isize;
                        } else {
                            lb = m as isize;
                        }
                    }
                }
                step = (ub - lb) / 2
            }

            if is_lower {
                if ub as usize == self.len() {
                    Err(self.len())
                } else {
                    let ub = ub as usize;
                    match f(&self[ub]) {
                        Ordering::Equal => {
                            Ok(ub)
                        },
                        _ => {
                            Err(ub)
                        }
                    }
                }
            } else {
                if lb == -1 {
                    Err(0)
                } else {
                    let lb = lb as usize;
                    match f(&self[lb]) {
                        Ordering::Equal => {
                            Ok(lb)
                        },
                        _ => {
                            Err(lb+1)
                        }
                    }
                }
            }
        }

        fn find_bound_by_key<'a, B, F>(&'a self, b: &B, mut f: F, is_lower: bool) -> Result<usize, usize>
            where F: FnMut(&'a Self::Item) -> B,
                  B: Ord {
            self.find_bound_by(|elem|{ f(elem).cmp(b) }, is_lower)
        }

    }
}

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

    #[test]
    fn test_find_bound_by() {
        let s = [0, 2, 2, 2, 4];
        // lower bound
        let seek = 2;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Ok(1));
        let seek = 1;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(1));
        let seek = -1;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(0));
        let seek = 5;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(5));
        // upper bound
        let seek = 2;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Ok(3));
        let seek = 1;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(1));
        let seek = 5;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(5));
        let seek = -1;
        assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(0));
    }
}


use std::io;

fn main() -> io::Result<()> {
    let mut input = String::new();

    io::stdin().read_line(&mut input)?;

    let n = input.trim().parse::<usize>().unwrap();

    match n % 2 {
        0 => println!("Mahmoud"),
        1 => println!("Ehab"),
        _ => println!("Invalid number"),
    }

    Ok(())
}


use std::io;

fn main() {

    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let n = line.trim().parse::<u64>().unwrap();

    if n % 2 == 0 {
        println!("Mahmoud")
    } else {
        println!("Ehab")
    }
}


use std::io;

fn get_line() -> io::Result<String> {
	let mut buffer = String::new();

	io::stdin().read_line(&mut buffer)?;
	Ok(buffer)
}

fn main() {
	let input = get_line().unwrap();
	let n: u32 = input.trim().parse().unwrap();

	print!("{}", if n % 2 == 0 { "Mahmoud" } else { "Ehab" });
}


use std::io;

fn main() {
    let mut val = String::new();

    io::stdin().read_line(&mut val)
        .expect("Не удалось прочитать строку");

    let val: u32 = val.trim().parse()
        .expect("Пожалуйста, введите число!");

    if val % 2 == 0 {
        println!("Mahmoud");
    } else {
        println!("Ehab");
    }
}


use std::iter::*;

fn main() {
    let mut inp = ReadIn::new();
    let n = inp.int() as usize;
    let dices: Vec<Vec<i32>> = repeat(()).take(n).map(|_| inp.intvec()).collect();
    let mut res = nums(&dices);
    res.sort();
    let cnt = res.iter().scan(0, |p, &el| {
        if *p + 1 >= el {
            *p = el;
            Some(el)
        } else { None }
    }
    ).last().unwrap();
    println!("{:?}", cnt);
}

fn nums(digs: &Vec<Vec<i32>>) -> Vec<i32> {
    if digs.is_empty() { vec![0] } else {
        digs.iter()
            .enumerate()
            .flat_map(|(i, v)| {
                let mut v1 = digs.clone();
                v1.remove(i);
                nums(&v1)
                    .into_iter()
                    .flat_map(move |n| v
                        .iter()
                        .map(move |d| n * 10 + d)
                        .chain(once(n)))
            })
            .collect()
    }
}

use std::str::SplitWhitespace;
use std::io::stdin;
use std::mem::forget;

pub struct ReadIn(pub String);

impl ReadIn {
    pub fn new() -> ReadIn { ReadIn(String::new()) }
    fn read_i32(s: &str) -> i32 { s.parse().unwrap() }
    pub fn read_line(&mut self) {
        self.0.clear();
        forget(stdin().read_line(&mut self.0));
    }
    pub fn ints(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.0.split_whitespace().map(ReadIn::read_i32)
    }
    pub fn intvec(&mut self) -> Vec<i32> { self.ints().collect() }
    pub fn int(&mut self) -> i32 { self.ints().next().unwrap() }
    pub fn int2(&mut self) -> (i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap())
    }

    pub fn int3(&mut self) -> (i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
    pub fn int4(&mut self) -> (i32, i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
}


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

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

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

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

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let n: usize = get_line().trim().parse().unwrap();

    let cubes: Vec<_> = BufReader::new(io::stdin()).lines()
        .map(|s| {
            let s = s.unwrap();
            let mut cube = [false; 10];
            for s in s.split_whitespace() {
                let d = s.bytes().last().unwrap();
                let d = (d - b'0') as usize;
                cube[d] = true;
            }
            cube
        }).collect();

    let perms = match n {
        3 => vec![
            vec![0, 1, 2],
            vec![0, 2, 1],
            vec![1, 0, 2],
            vec![1, 2, 0],
            vec![2, 0, 1],
            vec![2, 1, 0],
        ],
        2 => vec![
            vec![0, 1],
            vec![1, 0],
        ],
        1 => vec![vec![0]],
        _ => panic!(""),
    };

    let fact = |n| {
        let mut ret_val = 1;
        for i in 0..n {
            ret_val *= i + 1;
        }
        ret_val
    };

    let check = |x| {
        let x = format!("{}", x);
        for perm in perms.iter().take(fact(n)) {
            let p = x.bytes().map(|b| (b - b'0') as usize)
                .zip(perm.iter()).all(|(d, &i)| cubes[i][d]);
            if p {
                return true;
            }
        }
        false
    };

    for i in 1.. {
        if !check(i) {
            println!("{}", i - 1);
            return;
        }
    }
}


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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: usize = util::get();
    let ss: Vec<Vec<usize>> = (0..n)
        .map(|_| {
            let mut v: Vec<usize> = util::gets();
            v.sort();
            v
        })
        .collect();

    let ans = (1..)
        .take_while(|&x| if x < 10 {
            ss.iter().any(|v| v.binary_search(&x).is_ok())
        } else if x < 100 {
            let a1 = x % 10;
            let a2 = x / 10;

            let h1 = (0..ss.len())
                .filter(|&i| ss[i].binary_search(&a1).is_ok())
                .collect::<HashSet<_>>();
            let h2 = (0..ss.len())
                .filter(|&i| ss[i].binary_search(&a2).is_ok())
                .collect::<HashSet<_>>();

            (h1.len() > 1 && h2.len() > 1) ||
                (h1.len() > 0 && h2.len() > 0 &&
                     (h1.difference(&h2).count() != 0 || h2.difference(&h1).count() != 0))

        } else {
            let perm = vec![
                vec![0, 1, 2],
                vec![0, 2, 1],
                vec![1, 0, 2],
                vec![1, 2, 0],
                vec![2, 0, 1],
                vec![2, 1, 0],
            ];

            let a1 = x % 10;
            let a2 = x / 10 % 10;
            let a3 = x / 100;
            let a = vec![a1, a2, a3];

            if n < 3 {
                false
            } else {
                perm.iter().any(|p| {
                    p.iter().zip(a.iter()).all(|(&i, &k)| {
                        ss[i].binary_search(&k).is_ok()
                    })
                })
            }

        })
        .last();

    if let Some(a) = ans {
        println!("{}", a);
    } else {
        println!("0");
    }

}


use std::iter::*;

fn main() {
    let mut inp = ReadIn::new();
    let n = inp.int() as usize;
    let dices: Vec<Vec<i32>> = repeat(()).take(n).map(|_| inp.intvec()).collect();
    let mut res: Vec<i32> = nums(dices).collect();
    res.sort();
    let cnt = res.iter().scan(0, |p, &el| {
        if *p + 1 >= el {
            *p = el;
            Some(el)
        } else { None }
    }
    ).last().unwrap();
    println!("{:?}", cnt);
}

fn nums<'a>(digs: Vec<Vec<i32>>) -> Box<Iterator<Item=i32> + 'a> {
    if digs.is_empty() { Box::new(once(0)) } else {
        let d1 = digs.clone();
        Box::new(d1.into_iter()
            .enumerate()
            .flat_map(move |(i, v)| {
                let mut v1 = digs.clone();
                v1.remove(i);
                nums(v1)
                    .into_iter()
                    .flat_map(move |n|
                        v.clone()
                            .into_iter()
                            .map(move |d| n * 10 + d)
                            .chain(once(n)))
            }))
    }
}

use std::str::SplitWhitespace;
use std::io::stdin;
use std::mem::forget;

pub struct ReadIn(pub String);

impl ReadIn {
    pub fn new() -> ReadIn { ReadIn(String::new()) }
    fn read_i32(s: &str) -> i32 { s.parse().unwrap() }
    pub fn read_line(&mut self) {
        self.0.clear();
        forget(stdin().read_line(&mut self.0));
    }
    pub fn ints(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.0.split_whitespace().map(ReadIn::read_i32)
    }
    pub fn intvec(&mut self) -> Vec<i32> { self.ints().collect() }
    pub fn int(&mut self) -> i32 { self.ints().next().unwrap() }
    pub fn int2(&mut self) -> (i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap())
    }

    pub fn int3(&mut self) -> (i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
    pub fn int4(&mut self) -> (i32, i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
}


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

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

fn check(dice: &[[i32; 6]], digits: &[i32]) -> bool {
    if dice.len() < digits.len() {
        println!("a");
        false
    } else if digits.len() == 0 {
        true
    } else {
        let mut leftover_dice: Vec<[i32; 6]> = dice[1..].iter().cloned().collect();
        let mut has_solution = false;
        for (i, &die) in dice.iter().enumerate() {
            if die.iter().any(|&a| a == digits[0]) && check(&leftover_dice, &digits[1..]) {
                has_solution = true;
                break;
            }
            if i < leftover_dice.len() {
                leftover_dice[i] = die;
            }
        }
        has_solution
    }
}

fn main() {
    let n = scan_line!(i32);
    let mut dice = Vec::new();
    for _ in 0..n {
        let (a, b, c, d, e, f) = scan_line!(i32, i32, i32, i32, i32, i32);
        dice.push([a, b, c, d, e, f]);
    }
    let mut max_valid = 0;
    for i in 1.. {
        let mut digits = Vec::new();
        let mut j = i;
        while j > 0 {
            digits.push(j % 10);
            j /= 10;
        }
        let is_valid = check(&dice, &digits);
        if is_valid {
            max_valid = i;
        } else {
            break;
        }
    }
    println!("{}", max_valid);
}


use std::io::stdin;
fn main() {
    let mut text = String::new();
    stdin().read_line(&mut text).unwrap();
    let text: Vec<usize> = text
        .trim()
        .split_whitespace()
        .collect::<Vec<&str>>()
        .iter()
        .map(|e| e.parse().unwrap())
        .collect();
    let (a, b) = (text[0], text[1]);
    let mut values = vec![];
    if a == truc(b, a, &mut values) {
        println!("YES");
        println!("{}", values.len());
        let mut text = String::new();
        text.push_str(a.to_string().as_str());
        for i in (0..(values.len() - 1)).rev() {
            text = format!("{} {}", text, values[i]);
        }
        println!("{}", text)
    } else {
        println!("NO")
    }
}

fn truc(i: usize, b: usize, v: &mut Vec<usize>) -> usize {
    v.push(i);
    if i == b {
        i
    } else if i % 10 == 1 && i > 1 {
        truc((i - 1) / 10, b, v)
    } else if i % 2 == 0 {
        truc(i / 2, b, v)
    } else {
        i
    }
}


use std::io;

fn read_line() -> io::Result<String> {
    let mut input_str = String::new();

    try!(io::stdin().read_line(&mut input_str));

    Ok(input_str)
}

fn a_to_b(a: u32, b: u32) -> Vec<u32> {
    let mut result = Vec::new();
    let mut current_state = b;

    loop {
        match current_state {
            x if (x < a) || (x > a && x % 2 != 0 && x % 10 != 1) => {
                result.clear();
                break;
            }
            x => {
                result.push(x);
                match x {
                    x if x == a => break,
                    x if x % 2 == 0 => current_state /= 2,
                    _ => current_state /= 10,
                }
            }
        }
    }

    result.reverse();
    result
}

fn main() {
    let input_line = read_line().expect("Failed to read line.");
    let mut input_line_iter = input_line.split_whitespace();

    let given_number = input_line_iter.next()
        .expect("First number is not given.")
        .parse::<u32>()
        .expect("First number is invalid.");
    let result_number = input_line_iter.next()
        .expect("Second number is not given.")
        .parse::<u32>()
        .expect("Second number is invalid");

    let answer_sequence = a_to_b(given_number, result_number);

    match answer_sequence.len() {
        0 => println!("NO"),
        len => {
            println!("YES\n{}", len);
            for number in answer_sequence {
                print!("{} ", number);
            }
        }
    }
}


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

struct Reader {}

impl Reader {
    #[allow(unused)]
    fn read_string() -> String {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string).unwrap();
        string.trim().to_string()
    }

    #[allow(unused)]
    fn read_tokens() -> Vec::<String> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string).unwrap();
        let mut v = Vec::new();
        for value in string.split_whitespace() {
            v.push(value.to_string());
        }
        v
    }
}

//mod math;
//mod binary_search;
//mod graph;

fn generate(value: i64, limit: i64, list: Vec<i64>, res: &mut Vec<i64>) {
    if value == limit {
        *res = list.clone();
    }

    let next_value = value * 2;
    if next_value <= limit {
        let mut v = list.clone();
        v.push(next_value);
        generate(next_value, limit, v, res);
    }
    let next_value = value * 10 + 1;
    if next_value <= limit {
        let mut v = list.clone();
        v.push(next_value);
        generate(next_value, limit, v, res);
    }
}

fn main() {
    let tokens = Reader::read_tokens();
    let a = tokens[0].parse::<i64>().unwrap();
    let b = tokens[1].parse::<i64>().unwrap();

    let mut res = Vec::<i64>::new();

    generate(a, b, vec![a], &mut res);

    match res.len() > 1  {
        true => {
            println!("YES");
            println!("{}", res.len());
            for value in res {
                print!("{} ", value);
            }

        },
        _ => {
            println!("NO");
        }
    }
}


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

fn read_numbers() -> (i64, i64) {
    let stdin = io::stdin();
    let mut input = String::new();
    stdin.read_line(&mut input);
    let data: Vec<i64> = input
        .split_whitespace()
        .map(|x| i64::from_str(x).unwrap())
        .collect();
    (data[0], data[1])
}

fn rec(a: i64, b: i64, result: &mut Vec<i64>) -> bool {
    if a > b {
        return false;
    }

    if a == b || rec(10 * a + 1, b, result) == true || rec(2 * a, b, result) == true {
        result.push(a);
        return true;
    }

    false
}

fn main() {
    let (a, b) = read_numbers();
    let mut vec: Vec<i64> = vec![];
    let yes = rec(a, b, &mut vec);

    if yes == true {
        println!("YES");
        println!("{}", vec.len());

        for i in vec.iter().rev() {
            print!("{} ", i);
        }
    } else {
        println!("NO");
    }
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU

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

    let n = get!(usize);
    let mut xs = vec![];
    for _ in 0..n {
        let x = get!();
        xs.push(x);
    }
    xs.sort();
    let mut ans = 0;
    for i in 0..n/2 {
        ans += xs[i*2+1]-xs[i*2];
    }
    println!("{}", ans);
}


use std::io::{stdin};

fn main() {
  let mut students_count = String::new();
  stdin().read_line(&mut students_count).expect("expected count input");
  let _count : u32 = students_count.trim().parse().unwrap();
  let mut students_score = String::with_capacity(500);
  stdin().read_line(&mut students_score).expect("expected students score");
  let mut scores_arr : Vec<u32> = students_score.trim().split(" ")
                      .map(|score| score.parse::<u32>().unwrap())
                      .collect();
  scores_arr.sort();
  let mut problems_to_solve : u32 = 0;
  for i in (0..(scores_arr.len() - 1)).step_by(2) {
    let diff : u32 = scores_arr[i + 1] - scores_arr[i];
    problems_to_solve = problems_to_solve + diff;
  }
  println!("{}", problems_to_solve);
}


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

fn partition(array: &mut [i32], mut left_index: usize, mut right_index: usize) -> usize {
    let pivot_element = array[(left_index + right_index) >> 1];
    loop {
        while array[left_index] < pivot_element {
            left_index += 1;
        }
        while array[right_index] > pivot_element {
            right_index -= 1;
        }
        if left_index >= right_index {
            break;
        }
        array.swap(left_index, right_index);
        left_index += 1;
        right_index -= 1;
    }
    return right_index;
}

fn qsort(array: &mut [i32], left: usize, right: usize) {
    if left < right {
        let p = partition(array, left, right);
        qsort(array, left, p);
        qsort(array, p + 1, right);
    }
}

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

    let mut val = String::new();
    io::stdin().read_line(&mut val)
        .expect("Не удалось прочитать строку");

    let mut numbers: Vec<i32> =
        reader.lock()                           // (0)
            .lines().next().unwrap().unwrap() // (1)
            .split(' ').map(|s| s.trim())     // (2)
            .filter(|s| !s.is_empty())        // (3)
            .map(|s| s.parse().unwrap())      // (4)
            .collect();                       // (5)

    let length = numbers.len();
    qsort(numbers.as_mut_slice(), 0, length - 1);
    let mut total = 0;
    let mut i = 0;
    while i < length - 1 {
        total += numbers[i + 1] - numbers[i];
        i += 2;
    }
    println!("{}", total);
}


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

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

    let mut skill_levels: Vec<i32> = buffer
        .lines()
        .nth(1)
        .expect("all lines but first")
        .split(' ')
        .map(|s| s.parse::<i32>().expect("skill level")).collect();
    skill_levels.sort();
    let num_problems: i32 = (0..(skill_levels.len() / 2))
        .map(|idx| skill_levels[idx * 2 + 1] - skill_levels[idx * 2])
        .sum();

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


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

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

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

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

use std::f64;

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

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

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

#[derive(Debug)]
struct Info {
    n: i64,
    k: i64,
    m: i64,
    ans: Vec<i64>,
}

impl Info {
    fn rec(&mut self, crt: i64) {
        //debug!(crt, self);
        if self.m == self.k || crt == 1 {
            self.ans.push(crt);
            return;
        }

        self.m += 1;
        self.rec(crt/2);
        self.rec(crt/2);
    }
}

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

    //'outer: for _ in 0..t {
        let n:usize = read();
        let mut a:Vec<i64> = (0..n).map(|_| read()).collect();
        a.sort();
        let mut ans = 0;
        for i in (0..n).step_by(2) {
            ans += a[i+1]-a[i];
        }
        println!("{}", ans);
    //}
}

/*

*/


use std::io;
use std::io::*;
use std::vec;
use std::vec::*;
fn main(){

    let mut N = String::new();
    io::stdin().read_line(&mut N);
    let mut N =  N.trim().parse::<i32>().unwrap();

    let mut nums_line = String::new();
    io::stdin().read_line(&mut nums_line);

    let mut nums : Vec<i32> = nums_line.split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    nums.sort();

    let mut sum = 0;
    let mut i = 0;
    while i < N-1{
        sum = sum + nums[i as usize +1] - nums[i as usize];
        i = i + 2;
    }
    println!("{}", sum);
}


use std::{io, process};

fn main() {
	let n: u8 = {
		let mut line = String::new();
		io::stdin().read_line(&mut line).unwrap();
		line.trim().parse().unwrap()
	};

	let mut a: Vec<u8> = {
		let mut line = String::new();
		io::stdin().read_line(&mut line).unwrap();
		line.trim().split(' ').map(|a| a.parse().unwrap()).collect()
	};

	a.sort();

	// remove duplicates
	let mut i = a.len() - 1;
	loop {
		for j in (0..a.len()).rev() {
			if i == j {
				continue;
			}
			if a[i] == a[j] {
				if i > j {
					a.remove(i);
					a.remove(j);
				} else {
					a.remove(j);
					a.remove(i);
				}
				i -= 1;
				break;
			}
		}

		if i == 0 {
			break;
		}
		i -= 1;
	}

	assert!(a.len() % 2 == 0);

	let mut pb0 = 0u32;
	for s in a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 0)
		.map(|s| *s.1)
		.zip(a.iter().enumerate().filter(|s| s.0 % 2 == 1).map(|s| *s.1))
	{
		pb0 += s.1 as u32 - s.0 as u32;
	}

	if a.len() < 3 {
		println!("{}", pb0);
		process::exit(0);
	}

	let mut pb1 = 0u32;
	let mut b: Vec<u8> = a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 0)
		.map(|s| *s.1)
		.collect();
	b.remove(0);
	let lasti = b.len() - 1;
	b.remove(lasti);
	for s in a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 1)
		.map(|s| *s.1)
		.zip(b)
	{
		pb1 += s.1 as u32 - s.0 as u32;
	}
	pb1 += a[a.len() - 1] as u32 - a[0] as u32;

	println!("{}", pb0.min(pb1));
}


use std::io;
use std::io::*;
use std::vec;
use std::vec::*;
macro_rules! in_seq{
    ($x:ident) => {
        let mut nums_line = String::new();
        io::stdin().read_line(&mut nums_line);
        let mut $x : Vec<i32> = nums_line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect();
    }
}

fn main(){
    in_seq!(N);
    let N = N[0];

    in_seq!(nums);

    nums.sort();

    let mut sum = 0;
    let mut i = 0;
    while i < N-1{
        sum = sum + nums[i as usize +1] - nums[i as usize];
        i = i + 2;
    }
    println!("{}", sum);
}


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

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

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

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

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

fn main() {
  let (a,b) = readln!(i64,i64);
  let res = gcd(a,b);
  println!("{}",res);
}


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

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

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

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

    let mut a: i64 = input.p();
    let mut b: i64 = input.p();
    let mut sol = 0;
    while b > 0 {
        sol += a / b;
        let t = a % b;
        a = b;
        b = t;
    }
    println!("{}", sol);
}


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let size = s.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect::<Vec<i32>>();
    let mut c = -1;
    if size.iter().fold(true, |acc, &x| acc && (x==0)) == true {
        c=-1;
    } else {
    for i  in 0..=100 {
        if size.iter().map(|x| x-i).sum::<i32>() == 0 {
           c = i;
           break;
        }
    }
    }
    println!("{}",c );
}


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

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

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

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

fn main() {
    let a = readvec!(i32);
    let b = a.iter().fold(0,|x,y| x+y);
    println!("{}",if b > 0 && b%a.len() as i32 == 0 { b/a.len() as i32 } else { -1 });
}


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

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

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

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

}

fn _main() {
    let mut scan = Scan::new();
    let bets: Vec<usize> = scan.next_n(5);
    let total: usize = bets.iter().sum();
    let (valid, result) = (total%5==0 && total!=0, total/5);
    if valid {
        println!("{}", result);
    } else {
        println!("-1");
    }
}

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


// {{{ by shik

use std::io;

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

#[allow(unused_macros)]
macro_rules! R {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::<Vec<_>>()
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

#[allow(unused_macros)]
macro_rules! W {
    ( $x:expr ) => {{
        println!("{}", $x);
    }};
    ( $x:expr, $($xs:expr),* ) => {{
        print!("{} ", $x);
        W!($($xs),*);
    }}
}

#[allow(unused_macros)]
macro_rules! join {
    ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }
}

#[allow(unused_macros)]
macro_rules! dump {
    ($($x:expr),*) => {
        eprintln!(join!($(concat!(stringify!($x), " = {:?}")),*; ", "), $($x),*);
    }
}

// }}}

fn main() {
    let s: i32 = R!(i32, ...).into_iter().sum();
    println!("{}", if s % 5 == 0 && s > 0 { s / 5 } else { -1 });
}


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

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

    let sum = (0..5).map(|_| input.i()).sum::<i32>();
    let sol = if sum % 5 == 0 && sum > 0 {
        sum / 5
    } else {
        -1
    };
    println!("{}", sol);
}