import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.stream.LongStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GXMouseInTheCampus solver = new GXMouseInTheCampus();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GXMouseInTheCampus {
        LongHashMap mu = new LongHashMap(100000, false);
        LongHashMap euler = new LongHashMap(100000, false);
        long[] primes;

        {
            mu.put(1, 1);
            euler.put(1, 1);
        }

        public long oneOfPrimeFactor(long x) {
            for (long p : primes) {
                if (x % p == 0) {
                    return p;
                }
            }
            return x;
        }

        public void populate(long x) {
            long factor = oneOfPrimeFactor(x);
            long cnt = 0;
            long y = x;
            while (y % factor == 0) {
                cnt++;
                y /= factor;
            }
            if (cnt > 1) {
                mu.put(x, 0);
            } else {
                mu.put(x, -mu(y));
            }
            euler.put(x, euler(y) * (x / y - x / y / factor));
        }

        public long mu(long x) {
            long ans = mu.getOrDefault(x, -1);
            if (ans == -1) {
                populate(x);
                ans = mu.get(x);
            }
            return ans;
        }

        public long euler(long x) {
            long ans = euler.getOrDefault(x, -1);
            if (ans == -1) {
                populate(x);
                ans = euler.get(x);
            }
            return ans;
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            long m = in.readLong();
            long x = in.readLong();

            primes = new LongPollardRho().findAllFactors(m).keySet()
                    .stream().mapToLong(Long::longValue).toArray();
            LongList allFactorOfM = new LongList(20000);
            LongList tmpList = new LongList(20000);
            LongList allPossiblePrimeFactor = new LongList();
            for (long p : primes) {
                allPossiblePrimeFactor.add(p);
                allPossiblePrimeFactor.addAll(Factorization.factorizeNumberPrime(p - 1));
            }
            allPossiblePrimeFactor.unique();

            collect(allFactorOfM, m, 0);
            LongPower power = new LongPower(ILongModular.getInstance(m));

            long total = 1;
            for (int i = 0; i < allFactorOfM.size(); i++) {
                long g = allFactorOfM.get(i);
                if (g == m) {
                    continue;
                }
                long mg = m / g;
                tmpList.clear();
                collect(tmpList, mg, 0);
                long cnt = 0;
                for (int j = tmpList.size() - 1; j >= 0; j--) {
                    long t = tmpList.get(j);
                    cnt += mu(t) * ((m - 1) / (t * g));
                }

                tmpList.clear();
                long euler = euler(mg);
                LongList primeFactors = tmpList;
                for (int j = 0; j < allPossiblePrimeFactor.size(); j++) {
                    long p = allPossiblePrimeFactor.get(j);
                    if (euler % p == 0) {
                        primeFactors.add(p);
                    }
                }

                long n = euler;
                for (int j = 0; j < primeFactors.size(); j++) {
                    long p = primeFactors.get(j);
                    while (n % p == 0 && power.pow(x, n / p) % mg == 1) {
                        n /= p;
                    }
                }

                if (cnt % n != 0) {
                    throw new IllegalStateException();
                }
                total += cnt / n;
            }

            out.println(total);
        }

        public void collect(LongList list, long x, int i) {
            if (i == primes.length) {
                list.add(x);
                return;
            }
            collect(list, x, i + 1);
            while (x % primes[i] == 0) {
                x /= primes[i];
                collect(list, x, i + 1);
            }
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static long round(double x) {
            if (x >= 0) {
                return (long) (x + 0.5);
            } else {
                return (long) (x - 0.5);
            }
        }

        public static long mod(long x, long mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return x;
        }

        public static long mulMod(long a, long b, long mod) {
            long k = DigitUtils.round((double) a / mod * b);
            return DigitUtils.mod(a * b - k * mod, mod);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(long c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class LongPower {
        final ILongModular modular;

        public LongPower(ILongModular modular) {
            this.modular = modular;
        }

        public long pow(long x, long n) {
            if (n == 0) {
                return 1;
            }
            long r = pow(x, n >> 1);
            r = modular.mul(r, r);
            if ((n & 1) == 1) {
                r = modular.mul(r, x);
            }
            return r;
        }

    }

    static class Factorization {
        public static LongList factorizeNumberPrime(long x) {
            LongList ans = new LongList();
            for (long i = 2; i * i <= x; i++) {
                if (x % i != 0) {
                    continue;
                }
                ans.add(i);
                while (x % i == 0) {
                    x /= i;
                }
            }
            if (x > 1) {
                ans.add(x);
            }
            return ans;
        }

    }

    static class LongHashMap {
        private int[] slot;
        private int[] next;
        private long[] keys;
        private long[] values;
        private int alloc;
        private boolean[] removed;
        private int mask;
        private int size;
        private boolean rehash;

        public LongHashMap(int cap, boolean rehash) {
            this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;
            slot = new int[mask + 1];
            next = new int[cap + 1];
            keys = new long[cap + 1];
            values = new long[cap + 1];
            removed = new boolean[cap + 1];
            this.rehash = rehash;
        }

        private void doubleCapacity() {
            int newSize = Math.max(next.length + 10, next.length * 2);
            next = Arrays.copyOf(next, newSize);
            keys = Arrays.copyOf(keys, newSize);
            values = Arrays.copyOf(values, newSize);
            removed = Arrays.copyOf(removed, newSize);
        }

        public void alloc() {
            alloc++;
            if (alloc >= next.length) {
                doubleCapacity();
            }
            next[alloc] = 0;
            removed[alloc] = false;
            size++;
        }

        private void rehash() {
            int[] newSlots = new int[Math.max(16, slot.length * 2)];
            int newMask = newSlots.length - 1;
            for (int i = 0; i < slot.length; i++) {
                if (slot[i] == 0) {
                    continue;
                }
                int head = slot[i];
                while (head != 0) {
                    int n = next[head];
                    int s = hash(keys[head]) & newMask;
                    next[head] = newSlots[s];
                    newSlots[s] = head;
                    head = n;
                }
            }
            this.slot = newSlots;
            this.mask = newMask;
        }

        private int hash(long x) {
            int h = Long.hashCode(x);
            return h ^ (h >>> 16);
        }

        public void put(long x, long y) {
            put(x, y, true);
        }

        public void put(long x, long y, boolean cover) {
            int h = hash(x);
            int s = h & mask;
            if (slot[s] == 0) {
                alloc();
                slot[s] = alloc;
                keys[alloc] = x;
                values[alloc] = y;
            } else {
                int index = findIndexOrLastEntry(s, x);
                if (keys[index] != x) {
                    alloc();
                    next[index] = alloc;
                    keys[alloc] = x;
                    values[alloc] = y;
                } else if (cover) {
                    values[index] = y;
                }
            }
            if (rehash && size >= slot.length) {
                rehash();
            }
        }

        public long getOrDefault(long x, long def) {
            int h = hash(x);
            int s = h & mask;
            if (slot[s] == 0) {
                return def;
            }
            int index = findIndexOrLastEntry(s, x);
            return keys[index] == x ? values[index] : def;
        }

        public long get(long x) {
            return getOrDefault(x, 0);
        }

        private int findIndexOrLastEntry(int s, long x) {
            int iter = slot[s];
            while (keys[iter] != x) {
                if (next[iter] != 0) {
                    iter = next[iter];
                } else {
                    return iter;
                }
            }
            return iter;
        }

        public LongEntryIterator iterator() {
            return new LongEntryIterator() {
                int index = 1;
                int readIndex = -1;

                public boolean hasNext() {
                    while (index <= alloc && removed[index]) {
                        index++;
                    }
                    return index <= alloc;
                }

                public long getEntryKey() {
                    return keys[readIndex];
                }

                public long getEntryValue() {
                    return values[readIndex];
                }

                public void next() {
                    if (!hasNext()) {
                        throw new IllegalStateException();
                    }
                    readIndex = index;
                    index++;
                }
            };
        }

        public String toString() {
            LongEntryIterator iterator = iterator();
            StringBuilder builder = new StringBuilder("{");
            while (iterator.hasNext()) {
                iterator.next();
                builder.append(iterator.getEntryKey()).append("->").append(iterator.getEntryValue()).append(',');
            }
            if (builder.charAt(builder.length() - 1) == ',') {
                builder.setLength(builder.length() - 1);
            }
            builder.append('}');
            return builder.toString();
        }

    }

    static class LongPollardRho {
        LongMillerRabin mr = new LongMillerRabin();
        ILongModular modular;
        Random random = new Random();

        public long findFactor(long n) {
            if (mr.mr(n, 3)) {
                return n;
            }
            modular = ILongModular.getInstance(n);
            while (true) {
                long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);
                if (f != -1) {
                    return f;
                }
            }
        }

        private long findFactor0(long x, long c, long n) {
            long xi = x;
            long xj = x;
            int j = 2;
            int i = 1;
            while (i < n) {
                i++;
                xi = modular.plus(modular.mul(xi, xi), c);
                long g = GCDs.gcd(n, Math.abs(xi - xj));
                if (g != 1 && g != n) {
                    return g;
                }
                if (i == j) {
                    j = j << 1;
                    xj = xi;
                }
            }
            return -1;
        }

        public Map<Long, Long> findAllFactors(long n) {
            Map<Long, Long> map = new HashMap();
            findAllFactors(map, n);
            return map;
        }

        private void findAllFactors(Map<Long, Long> map, long n) {
            if (n == 1) {
                return;
            }
            long f = findFactor(n);
            if (f == n) {
                Long value = map.get(f);
                if (value == null) {
                    value = 1L;
                }
                map.put(f, value * f);
                return;
            }
            findAllFactors(map, f);
            findAllFactors(map, n / f);
        }

    }

    static class GCDs {
        private GCDs() {
        }

        public static long gcd(long a, long b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        private static long gcd0(long a, long b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public long readLong() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            long val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static interface LongEntryIterator {
        boolean hasNext();

        void next();

        long getEntryKey();

        long getEntryValue();

    }

    static class LongModular implements ILongModular {
        final long m;

        public LongModular(long m) {
            this.m = m;
        }

        public long mul(long a, long b) {
            return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;
        }

        public long plus(long a, long b) {
            return valueOf(a + b);
        }

        public long valueOf(long a) {
            a %= m;
            if (a < 0) {
                a += m;
            }
            return a;
        }

    }

    static class LongMillerRabin {
        ILongModular modular;
        LongPower power;
        Random random = new Random();

        public boolean mr(long n, int s) {
            if (n <= 1) {
                return false;
            }
            if (n == 2) {
                return true;
            }
            if (n % 2 == 0) {
                return false;
            }
            modular = ILongModular.getInstance(n);
            power = new LongPower(modular);
            for (int i = 0; i < s; i++) {
                long x = (long) (random.nextDouble() * (n - 2) + 2);
                if (!mr0(x, n)) {
                    return false;
                }
            }
            return true;
        }

        private boolean mr0(long x, long n) {
            long exp = n - 1;
            while (true) {
                long y = power.pow(x, exp);
                if (y != 1 && y != n - 1) {
                    return false;
                }
                if (y != 1 || exp % 2 == 1) {
                    break;
                }
                exp = exp / 2;
            }
            return true;
        }

    }

    static class LongModularDanger implements ILongModular {
        final long m;

        public LongModularDanger(long m) {
            this.m = m;
        }

        public long mul(long a, long b) {
            return DigitUtils.mulMod(a, b, m);
        }

        public long plus(long a, long b) {
            return valueOf(a + b);
        }

        public long valueOf(long a) {
            a %= m;
            if (a < 0) {
                a += m;
            }
            return a;
        }

    }

    static class LongList implements Cloneable {
        private int size;
        private int cap;
        private long[] data;
        private static final long[] EMPTY = new long[0];

        public LongList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new long[cap];
            }
        }

        public LongList(LongList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public LongList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public long get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(long x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(long[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(LongList list) {
            addAll(list.data, 0, list.size);
        }

        public void sort() {
            if (size <= 1) {
                return;
            }
            Randomized.shuffle(data, 0, size);
            Arrays.sort(data, 0, size);
        }

        public void unique() {
            if (size <= 1) {
                return;
            }

            sort();
            int wpos = 1;
            for (int i = 1; i < size; i++) {
                if (data[i] != data[wpos - 1]) {
                    data[wpos++] = data[i];
                }
            }
            size = wpos;
        }

        public int size() {
            return size;
        }

        public long[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public void clear() {
            size = 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof LongList)) {
                return false;
            }
            LongList other = (LongList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Long.hashCode(data[i]);
            }
            return h;
        }

        public LongList clone() {
            LongList ans = new LongList();
            ans.addAll(this);
            return ans;
        }

    }

    static class SequenceUtils {
        public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(long[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                long tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static interface ILongModular {
        long plus(long a, long b);

        long mul(long a, long b);

        static ILongModular getInstance(long mod) {
            //return new LongModularDanger(mod);
            return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Task_1749_D {

    public static final long MOD = 998244353L;
    public static final BigInteger MOD_BIG = BigInteger.valueOf(MOD);

    public static void main(String[] args) throws Exception {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            StringTokenizer tok = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(tok.nextToken());
            long m = Long.parseLong(tok.nextToken());

            BigInteger result = BigInteger.ZERO;
            BigInteger mBig = BigInteger.valueOf(m);
            BigInteger currValue = BigInteger.valueOf(m);
            long currDiv = 1L;
            boolean[] erat = eratosthenes(n);
            BigInteger total = BigInteger.valueOf(m);
            for (int i = 2; i <= n; i++) {
                total = total.multiply(mBig).remainder(MOD_BIG).add(MOD_BIG);
                if (!erat[i]) {
                    currDiv *= i;
                }
                currValue = currValue.multiply(BigInteger.valueOf(m / currDiv)).remainder(MOD_BIG);
                result = result.add(total).subtract(currValue).remainder(MOD_BIG);
            }

            System.out.println(result.longValue());
        }
    }

    private static boolean[] eratosthenes(int n) {
        boolean[] res = new boolean[n + 1];
        for (int i = 2; i * i <= n ; i++) {
            if(!res[i]) {
                for (int j = i * i; j <= n ; j += i) {
                    res[j] = true;
                }
            }
        }
        return res;
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class ivanTheFool {
    public static long mod = 1000000007;
    public static void fout(long x){
        System.out.println(x);
    }
    /**-----------fast reader------------*/
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    /**-----end of fast reader----------------*/

    public static long pmod(long  x,long  y){
        long r = 1;
        while(y > 0){
            if(y%2 == 1){
                r = (r * x)%mod;
            }
            x = (x * x)%mod;
            y >>= 1;
        }
        return r;
    }

    public static void main(String[] args) {
        FastReader rd = new FastReader();
        long n,m;
        n = rd.nextLong();
        m = rd.nextLong();
        long answer = 0;
        long []fact = new long[200000];
        fact[0] = 1;
        for(long i = 1;i<200000;++i){
            fact[(int)i] = (fact[(int)i-1]*i)%mod;
        }
        answer += 2;//all adj cells are different
        if(m >= 2){
            for(long blk = 1 ; blk <= (m/2);blk++){
                long bins = m - (2*blk) + 1;
                long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;
                sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;
                sub = (2 * sub)%mod;
                //fout(sub);
                answer = (answer + sub)%mod;
            }
        }
        if(n >= 2){
            for(long blk = 1 ; blk <= (n/2);blk++){
                long bins = n - (2*blk) + 1;
                long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;
                sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;
                sub = (2 * sub)%mod;
                answer = (answer + sub)%mod;
            }
        }
        // if(m == 1 ^ n == 1){
        //     answer = (answer + 2)%mod;
        // }
        fout(answer);
    }
}


import java.io.*;
import java.util.*;

public class CF1342E extends PrintWriter {
	CF1342E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1342E o = new CF1342E(); o.main(); o.flush();
	}

	static final int MD = 998244353;
	int[] ff, gg;
	long power(int a, int k) {
		if (k == 0)
			return 1;
		long p = power(a, k >> 1);
		p = p * p % MD;
		if ((k & 1) == 1)
			p = p * a % MD;
		return p;
	}
	long ch(int n, int k) {
		return (long) ff[n] * gg[k] % MD * gg[n - k] % MD;
	}
	void main() {
		int n = sc.nextInt();
		long k_ = sc.nextLong();
		if (k_ >= n) {
			println(0);
			return;
		}
		int c = n - (int) k_;
		ff = new int[n + n];
		gg = new int[n + n];
		for (int f = 1, i = 0; i < n + n; i++) {
			gg[i] = (int) power(ff[i] = f, MD - 2);
			f = (int) ((long) f * (i + 1) % MD);
		}
		long ans = 0;
		for (int a = 1; a <= c; a++) {
			long x = power(a, n) * ch(c, a) % MD;
			ans += (c - a) % 2 == 0 ? x : -x;
		}
		if ((ans %= MD) < 0)
			ans += MD;
		ans = ans * ch(n, c) % MD;
		if (k_ > 0)
			ans = ans * 2 % MD;
		println(ans);
	}
}


import java.util.*;

public class B_189_Counting_Rhombi {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt();
        long ans=0;
        for (int i=2;i<=n;i+=2){
            for (int j=2;j<=m;j+=2){
                ans+=(n-i+1)*(m-j+1);
            }
        }
        System.out.println(ans);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    QuickScanner in = new QuickScanner(inputStream);
    QuickWriter out = new QuickWriter(outputStream);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskB {
    char[][] board;

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      board = new char[9][9];
      for (int i = 0; i < 9; ++i)
        for (int j = 0; j < 9; ++j) {
          board[i][j] = (char) in.nextNonSpaceChar();
        }
      int x = (in.nextInt() - 1) % 3 * 3;
      int y = (in.nextInt() - 1) % 3 * 3;
      int count = 0;
      if (hasEmpty(x, y)) {
        for (int i = x; i < x + 3; ++i)
          for (int j = y; j < y + 3; ++j)
            if (board[i][j] == '.') {
              board[i][j] = '!';
            }
      } else {
        for (int i = 0; i < 9; ++i)
          for (int j = 0; j < 9; ++j)
            if (board[i][j] == '.') {
              board[i][j] = '!';
            }
      }
      for (int i = 0; i < 9; ++i) {
        if (i > 0 && i % 3 == 0) out.println();
        for (int j = 0; j < 9; ++j) {
          if (j > 0 && j % 3 == 0) out.print(' ');
          out.print(board[i][j]);
        }
        out.println();
      }
    }

    boolean hasEmpty(int x, int y) {
      for (int i = x; i < x + 3; ++i)
        for (int j = y; j < y + 3; ++j) {
          if (board[i][j] == '.') return true;
        }
      return false;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public QuickWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; ++i) {
        if (i > 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void println(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + (c - '0');
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }
}


import java.io.*;
import java.util.*;

public class D {

	static final int P = 1_000_000_007;

	void submit() {
		int n = nextInt();
		int[] dp = new int[n + 2];
		dp[0] = 1;
		for (int k = 1; k <= n; k++) {
			int[] nxt = new int[n + 1];
			int need = n + 1 - k;
			for (int i = 0; i <= need + 1; i++) {
				for (int j = 0; i + j - 1 <= need; j++) {
					int prod = (int) ((long) dp[i] * dp[j] % P);

					if (i + j <= need) {
						nxt[i + j] += prod;
						if (nxt[i + j] >= P) {
							nxt[i + j] -= P;
						}
						nxt[i + j] += (int) (2L * prod * (i + j) % P);
						if (nxt[i + j] >= P) {
							nxt[i + j] -= P;
						}

						if (i + j + 1 <= need) {
							nxt[i + j + 1] += prod;
							if (nxt[i + j + 1] >= P) {
								nxt[i + j + 1] -= P;
							}
						}
					}

					if (i + j > 0) {
						int mult = (i + j) * (i + j) - i - j;
						nxt[i + j - 1] += (int) ((long)mult * prod % P);
						if (nxt[i + j - 1] >= P) {
							nxt[i + j - 1] -= P;
						}
					}
				}
			}
			dp = nxt;
//			System.err.println(Arrays.toString(dp));
		}

		out.println(dp[1]);
	}

	void preCalc() {

	}

	void stress() {

	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new D();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Problem1 {

	static long a, b, c;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		HashMap< String, Integer> hm = new HashMap<>();
		hm.put("monday", 1);
		hm.put("tuesday", 2);
		hm.put( "wednesday", 3);
		hm.put("thursday",4);
		hm.put( "friday", 5);
		hm.put( "saturday", 6);
		hm.put("sunday", 7);
		String f = in.next();
		String s = in.next();
		int a = hm.get(f);
		int b = hm.get(s);
		for(int i = 0; i < 12; ++i)
		{
			int rem = (days[i]) % 7;
			if((a + rem) % 7 == b ||  ((a + rem) % 7 == 0 && b== 7 ))
			{
				out.println("YES");
				out.close();
				return;
			}

			if(a == b && rem == 0)
			{
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		out.close();

	}

	static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream stream) {
	        reader = new BufferedReader(new InputStreamReader(stream), 32768);
	        tokenizer = null;
	    }

	    public String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong()
	    {
	    	return Long.parseLong(next());
	    }

	}

}


//codeforces_975B

import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.*;

public class acm{

	public static void main(String args[]) throws IOException,FileNotFoundException {
		BufferedReader gi = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter go = new PrintWriter(System.out);
		int[] line = parseArray(gi.readLine().split(" "));
		int div,rem;
		long temp = 0,rez = 0;
		for (int k = 0; k<14; k++){
			if (line[k] == 0){ continue; }
			div = line[k]/14;
			rem = line[k]%14;
			temp = 0;
			for (int j = k+1; j<=k+rem; j++){
				if ((line[j%14]+div+1)%2==0){ temp += line[j%14] + 1 + div; }
			}
			for (int j = k+rem+1; j<14+k; j++){
				if ((line[j%14]+div)%2==0){ temp+= line[j%14] + div; }
			}
			if (div%2==0){temp+=div;}
			rez = max(rez, temp);
		}
		go.println(rez);
		go.close();
	}

	static int[]  parseArray(String[] line){
		int len = line.length;
		int A[] = new int[len];
		int k = 0;
		for (String e : line){
			A[k++] = Integer.parseInt(e);
		}
		return A;
	}

}


/*Author LAVLESH*/
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class solution{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st=new StringTokenizer("");

	static public String next() {
	        while (st == null || !st.hasMoreTokens()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return st.nextToken();
	    }

	static int mod=1000003;
	static int inv(int a){
		return BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod)).intValue();
	}
	public static void main(String[]args)throws IOException{
		PrintWriter op =new PrintWriter(System.out,true);
		long ans;
		int n=Integer.parseInt(next());
		 int m=Integer.parseInt(next());
		int num=1,den=1;
		 for(int i=1;i<=m;i++)
		 {
			 num=(int)((long)num*(n+i)%mod);
			 den=(int)((long)den*i%mod);
		 }
	ans=(((long)num*inv(den)%mod)+mod)%mod;
		op.println(ans-1);

		 op.close();
  }
}


import java.util.*;
public class A761 {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m =sc.nextInt();
        if(Math.abs(m-n) == 1 || (m+n!=0  && m==n) )
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BSquaresAndSegments solver = new BSquaresAndSegments();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSquaresAndSegments {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

//        Set<Long> fac = factors(n);
//
//        long ans = n + 1;
//        for (long f : fac) {
//            long t = n / f;
//
//            ans = Math.min(ans, t + f);
//        }
//
//        long sq = (long) Math.sqrt(n);
//
//        while (sq * sq < n)
//            sq++;
//
//        out.println(Math.min(2 * sq, ans));

            long ans = n + 1;
            for (int i = 1; i * i <= n; i++) {
                long ceil = (n + i - 1) / i;

                ans = Math.min(ans, i + ceil);
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}


import java.lang.*;
import java.math.BigInteger;
import java.io.*;
import java.util.*;

public class Solution implements Runnable{
    public static BufferedReader br;
    public static PrintWriter out;
    public static StringTokenizer stk;
    public static boolean isStream = true;

    public static void main(String[] args) throws IOException {
    	if (isStream) {
            br = new BufferedReader(new InputStreamReader(System.in));
        } else {
            br = new BufferedReader(new FileReader("in.txt"));
        }
        out = new PrintWriter(System.out);
        new Thread(new Solution()).start();
    }

    public void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    public String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return stk.nextToken();
    }

    public Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.valueOf(stk.nextToken());
    }

    public Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.valueOf(stk.nextToken());
    }

    public Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.valueOf(stk.nextToken());
    }

    public Float nextFloat() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Float.valueOf(stk.nextToken());
    }

    public void run() {
    	int n = nextInt();
    	int m = nextInt();
    	if (n > m) {
    		int sw = n;
    		n = m;
    		m = sw;
    	}
    	int[][] A = new int[1<<n][1<<n];
    	for (int m1 = 0; m1 < 1<<n; ++m1) { // Who goes out
    		for (int m2 = 0; m2 < 1<<n; ++m2) {  // Who comes
    			int[] arr = new int[n]; // Who remains
    			for (int i = 0; i < n; ++i) {
    				arr[i] = (~(m1>>i))&1;
    			}
    			int[] m2a = new int[n];
    			for (int i = 0; i < n; ++i) {
    				m2a[i] = (m2>>i)&1;
    			}
    			int cnt = 0;
    			for (int i = 0; i < n; ++i) {
    				if (arr[i] == 1) {
    					if (i > 0 && m2a[i-1] == 1) {
    						continue;
    					}
    					if (i < n-1 && m2a[i+1] == 1) {
    						continue;
    					}
    					if (m2a[i] == 1) {
    						continue;
    					}
    					if (i < n-1) {
    						m2a[i+1] = 1;
    					} else {
    						m2a[i] = 1;
    					}
    				}
    			}
    			for (int i = 0; i < n; ++i) {
    				if (m2a[i] == 1) {
    					cnt++;
    				}
    			}
    			A[m1][m2] = cnt;
    		}
    	}
    	int MAX = 10000;
    	int[][][] dp = new int[m+1][1<<n][1<<n];
    	for (int i = 0; i < m+1; i++) {
    		for (int m1 = 0; m1 < 1<<n; ++m1) {
    			Arrays.fill(dp[i][m1], MAX);
    		}
    	}

		dp[0][0][0] = 0;

    	for (int i = 0; i < m; i++) {
    		for (int m1 = 0; m1 < 1<<n; ++m1) {
    			for (int m2 = 0; m2 < 1<<n; ++m2) {
    				if (dp[i][m1][m2] != MAX) {
	    				for (int nm1 = 0; nm1 < 1<<n; ++nm1) {
	    	    			for (int nm2 = 0; nm2 < 1<<n; ++nm2) {
	    	        			if ((m1 & nm1) == 0) {
	    	        				int sm1 = m1|nm1;
	    	        				int sm2 = m2|nm2;
	    	        				int cnt = A[sm1][sm2];
	    	        				dp[i+1][nm2][nm1] = Math.min(dp[i+1][nm2][nm1], dp[i][m1][m2]+cnt);
	    	        			}
	    	        		}
	    	    		}
    				}
        		}
    		}
    	}

    	out.println(n*m-dp[m][0][0]);
    	out.flush();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CFTemplate {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		int[] arr = new int[4];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = in.nextInt();
		}

		boolean arithm = true;
		int d = arr[1] - arr[0];
		boolean geom = true;
		double q = arr[1] / arr[0];

		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i + 1] - arr[i] != d) arithm = false;
			if (arr[i] * arr[1] != arr[i + 1] * arr[0]) geom = false;
		}

		if (arithm) {
			out.println(arr[3] + d);
		} else if (geom) {
			if (arr[3] * arr[1] != arr[3] * arr[1] / arr[0] * arr[0]) {
				out.println(42);
			} else {
				out.println(arr[3] * arr[1] / arr[0]);
			}
		} else {
			out.println(42);
		}
		out.close();
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}
}


import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
		StringTokenizer sb=new StringTokenizer(in.readLine());
		long w=Long.parseLong(sb.nextToken());
		long[] cnt=new long[9];
		sb=new StringTokenizer(in.readLine());
		long tot=0;
		for (int i=1;i<=8;++i) {
			cnt[i]=Long.parseLong(sb.nextToken());
			long num=cnt[i]/(840/i);
			if (num>0) tot+=num-1;
			cnt[i]%=(840/i);
			if (num>0) cnt[i]+=840/i;
		}
		int maxW=840*16;
		if (w<maxW) maxW=(int)w;
		boolean[] dp=new boolean[maxW+1];
		dp[0]=true;
		long res=0;
		for (int i=1;i<=8;++i) {
			int num=(int)cnt[i];
			for (int j=0;j<20;++j) {
				if (num<=(1<<j)) break;
				num-=(1<<j);
				for (int k=maxW;k>=(1<<j)*i;--k)
					dp[k]|=dp[k-i*(1<<j)];
			}
			for (int k=maxW;k>=num*i;--k)
				dp[k]|=dp[k-num*i];
		}
		for (int i=0;i<=maxW;++i) if (dp[i])
			res=Math.max(res,i+Math.min((w-i)/840,tot)*840);
		out.println(res);
		out.close();
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.*;
public class Main {
	long N,a,b,c;

	public void solve() {
		N = nextLong();
		a = nextLong();
		b = nextLong();
		c = nextLong();

		if(a <= b - c){
			out.println(N / a);
			return;
		}
		long ans = 0L;

		if(b <= N){
			ans = (N - b) / (b - c) + 1;
			N -= ans * (b - c);
		}

		if(a <= N){
			ans += N / a;
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * 作者：张宇翔
 * 创建日期：2017年5月4日 下午10:33:03
 * 描述：永远的ACM，永远的征途
 */
public class Main {
	private static final int Max=(int) (1e5+10);
	private static int n;
	private static int ans;
	private static int []vis;
	public static void main(String[] args) throws Exception{
		InitData();
		GetAns();
	}
	private static void InitData() throws Exception{
		SC cin=new SC(System.in);
		vis=new int[Max];
		n=cin.nextInt();
		ans=0;
	}

	private static void GetAns(){
		if(n==3||n==4){
			System.out.println(1);
		}else if(n==2||n==1){
			System.out.println(0);
		}else{
			for(int i=1;i<=n;i++){
				int temp=(n+1)-i;
				if(i<temp){
					ans++;
					vis[i]=1;
					vis[temp]=1;
				}else{
					break;
				}
			}
			if(ans>1){
				ans--;
			}
			for(int i=1;i<=n;i++){
				if(vis[i]==0){
					ans++;
				}
			}
			System.out.println(ans);
		}
	}
	static class SC
	{
		BufferedReader br;
		StringTokenizer st;
		SC(InputStream s)
		{
			br = new BufferedReader(new InputStreamReader(s));
		}
		String next() throws IOException
		{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		int nextInt() throws NumberFormatException, IOException
		{
			return Integer.parseInt(next());
		}
		long nextLong() throws NumberFormatException, IOException
		{
			return Long.parseLong(next());
		}
	}

}


//package codeforces;

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();
		String str = sc.next();
		if (len < 2) {
			System.out.println(str);
		} else {
			String[] str_char = str.split("");
			StringBuffer sb = new StringBuffer("1");
			for (int i = 0; i < str_char.length; i++) {
				if(str_char[i].equals("0")){
					sb.append("0");
				}
			}
			System.out.println(sb);
		}

	}

}


import java.util.Arrays;
import java.util.Scanner;
import java.util.function.Function;

public class CF287D {

    public static long modPower(long base, long exponent, long mod) {
        long result = 1;
        while (exponent > 0) {
            if ((exponent & 1) != 0)
                result = (result * base) % mod;
            base = (base * base) % mod;
            exponent >>= 1;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        long m = in.nextLong();
        long[] dp = new long[k];
        dp[0] = 1;
        long total = 0;
        for (int i = 0; i < n; i++) {
            long[] next = new long[k];
            for (int j = 0; j < k; j++)
                for (int d = (i == n - 1) ? 1 : 0; d < 10; d++) {
                    int res = (int) (modPower(10, i, k) * d + j) % k;
                    next[res] = (next[res] + dp[j]) % m;
                }
            if (i < n - 1)
                total += (next[0] + m - 1) * 9 % m * modPower(10, n - 2 - i, m)
                        % m;
            else
                total += next[0];

            total %= m;
            dp = next;
            dp[0] = 1;
        }
        System.out.println(total);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////
    static int n;
    static int arr[];
    HashMap<String,String> hm=new HashMap<String,String>();
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        int a=sc.i();int b=sc.i();int c=sc.i();
        int a1=sc.i();int b1=sc.i();int c1=sc.i();
        if(a!=a1&&b!=b1&&c!=c1)
        System.out.println("NO");
        else
        System.out.println("YES");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class First
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class Team
{
    String teamName;
    int score;
    int goalFor;
    int goalAgainst;
    int matchPlayed;

    public Team(String teamName, int score, int goalFor, int goalAgainst, int matchPlayed)
    {
        super();
        this.teamName = teamName;
        this.score = score;
        this.goalFor = goalFor;
        this.goalAgainst = goalAgainst;
        this.matchPlayed = matchPlayed;
    }
}

class MyComparator implements Comparator<Team>
{
    @Override
    public int compare(Team t1, Team t2)
    {

        if(t1.score < t2.score) return 1;
        if(t1.score > t2.score) return -1;
        if(t1.goalFor - t1.goalAgainst < t2.goalFor - t2.goalAgainst) return 1;
        if(t1.goalFor - t1.goalAgainst > t2.goalFor - t2.goalAgainst) return -1;
        if(t1.goalFor < t2.goalFor) return 1;
        if(t1.goalFor > t2.goalFor) return -1;
        return t1.teamName.compareTo(t2.teamName);
    }
}

class TaskA
{
    public void solve(int testNumber, InputReader in, PrintWriter out)
    {
        Set <String> hset = new HashSet <String> ();
        String[] inputStr = new String[5];
        for(int i = 0; i < 5; i++)
        {
            inputStr[i] = in.nextLine();
        }

        Team[] team = new Team[4];
        for(int i = 0; i < 5; i++)
        {
            String str = inputStr[i];
            str = str.replace(":", " ");
            String[] ans = str.split("[ ]+");
            hset.add(ans[0]); hset.add(ans[1]);
        }
        int index = 0;
        for(String str : hset)
        {
            int myScore = 0;
            int myGoalFor = 0;
            int myGoalAgainst = 0;
            int matchPlayed = 0;
            for(int i = 0; i < 5; i++)
            {
                String current = inputStr[i];
                current = current.replace(":", " ");
                String[] ans = current.split("[ ]+");
                String firstTeam = ans[0];
                String secondTeam = ans[1];
                int firstScoreGoal = Integer.parseInt(ans[2]);
                int secondScoreGoal = Integer.parseInt(ans[3]);

                if(firstTeam.equals(str))
                {
                    myGoalFor += firstScoreGoal;
                    myGoalAgainst += secondScoreGoal;
                    if(firstScoreGoal > secondScoreGoal)
                    {
                        myScore += 3;
                    }
                    if(firstScoreGoal == secondScoreGoal)
                        myScore++;
                    matchPlayed++;
                }
                if(secondTeam.equals(str))
                {
                    myGoalFor += secondScoreGoal;
                    myGoalAgainst += firstScoreGoal;
                    if(secondScoreGoal > firstScoreGoal) myScore += 3;
                    if(secondScoreGoal == firstScoreGoal) myScore++;
                    matchPlayed++;
                }
            }
            team[index++] = new Team(str, myScore, myGoalFor, myGoalAgainst, matchPlayed);
        }
        Arrays.sort(team, new MyComparator());

        index = 0; int i = 0;
        for(Team item : team)
        {   if(item.teamName.equals("BERLAND"))
                index = i;
            i++;
            //System.out.println(item.teamName + " " + item.score + "  " + item.goalFor + "  " + item.goalAgainst + " " + item.matchPlayed);
        }
        if(team[0].teamName.equals("BERLAND") || team[1].teamName.equals("BERLAND"))
            out.println("1:0");

        else
        {
            String secondTeamName = team[1].teamName;
            int secondScore = team[1].score;
            int secondGoalFor = team[1].goalFor;
            int secondGoalAgainst = team[1].goalAgainst;
            int differenceSecond = secondGoalFor - secondGoalAgainst;

            int berlandScore = team[index].score;
            int berlandGoalFor = team[index].goalFor;
            int berlandGoalAgainst = team[index].goalAgainst;
            int differenceBerland = berlandGoalFor - berlandGoalAgainst;
            if(secondScore <= berlandScore + 2)
            {
                out.println("1:0");
            }
            else if (secondScore > berlandScore + 3)
            {
                out.println("IMPOSSIBLE");
            }
            else
            {
                int kk = 0;
                for(int k = 1; k < 4; k++)
                {
                    if(team[k].teamName.equals("BERLAND") == false && team[k].matchPlayed == 2)
                    {
                        kk = k;
                        break;
                    }
                }
                Team[] tempTeam = new Team[4];

                outer:for(int diff = 1; ; diff++)
                {

                int counter = 0; int hisGoals = 0;
                for(int myGoals = diff; ; myGoals++, hisGoals++)
                {

                    for(int step = 0; step < 4; step++)
                    {
                        tempTeam[step] = new Team(team[step].teamName, team[step].score, team[step].goalFor , team[step].goalAgainst, team[step].matchPlayed);
                    }

                    tempTeam[index].score += 3;
                    tempTeam[index].goalFor += myGoals;
                    tempTeam[index].goalAgainst += hisGoals;

                    tempTeam[kk].goalAgainst += myGoals;
                    tempTeam[kk].goalFor += hisGoals;

                    if(myGoals > 60) continue outer;
                    Arrays.sort(tempTeam, new MyComparator());
                    if(tempTeam[0].teamName.equals("BERLAND") || tempTeam[1].teamName.equals("BERLAND"))
                    {
                        out.println(myGoals + ":" + hisGoals);
                        break outer;
                    }
                }
                }
            }
        }
    }
}

class InputReader
{
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream)
    {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next()
    {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
        {
            try
            {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt()
    {
        return Integer.parseInt(next());
    }

    public String nextLine()
    {
        String inputLine = "";
        try
        {
            inputLine = reader.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return inputLine;
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Mathshow1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);

		int n = input.nextInt();
		int k = input.nextInt();
		int m = input.nextInt();
		int[] arr = new int[k];
		int total=0;
		for(int i=0; i<k;i++){
			arr[i] = input.nextInt();
			total+=arr[i];
		}
		int max=-1;
		Arrays.sort(arr);
		for(int i=0; i<=n;i++){
			int points = i*(k+1);
			long rem = m-i*total;
			if(rem <0 )continue;
			for(int j=0; j<k;j++){
				int picks = Math.min(n-i,(int)rem/arr[j]);
				if(picks==0){
					break;
				}
				points+=picks;
				rem-=picks*arr[j];
			}

			max = Math.max(points,max);
		}
		System.out.println(max);

	}

}


import java.util.*;
import java.io.*;
public class EdC {
	static long[] mods = {1000000007, 998244353, 1000000009};
	static long mod = mods[0];
	public static MyScanner sc;
    public static PrintWriter out;
    static int y;
	public static void main(String[] omkar) throws Exception{
		// TODO Auto-generated method stub
 		sc = new MyScanner();
 		out = new PrintWriter(System.out);
 		int n = sc.nextInt();
 		long k = sc.nextLong();
 		int[] array = readArrayInt(n);
 		y = 0;
 		int initial = 0;
 		for(int j =0;j<n;j++)
 			if (array[j] == 1)
 				y++;
 		for(int j =n-y;j<n;j++)
 			if (array[j] == 1)
 				initial++;
 		long[][] matrix = new long[y+1][y+1];
 		for(int j = 0;j<=y;j++){
 			long s = n;
 			s*=(long)(n-1);
 			s/=2;
 			if (j-1 >=0){
 				matrix[j-1][j]=j;
 				matrix[j-1][j]%=mod;
 				matrix[j-1][j]*=(long)(n-2*y+j);
 				matrix[j-1][j]%=mod;
 				s-=matrix[j-1][j];
 				s%=mod;
 				s+=mod;
 				s%=mod;
 			}
 			if (j+1 <= y){
 				matrix[j+1][j]=(y-j);
 				matrix[j+1][j]%=mod;
 				matrix[j+1][j]*=(long)(y-j);
 				matrix[j+1][j]%=mod;
 				s-=matrix[j+1][j];
 				s%=mod;
 				s+=mod;
 				s%=mod;
 			}
 			matrix[j][j] = s;

 		}
 		long[][] product = power(matrix, k);
 		long ans = product[y][initial];
 		ans%=mod;
 		long nC2 = n;
 		nC2*=(long)(n-1);
 		nC2/=2L;
 		long div = power(nC2, mod-2);
 		ans*=power(div, k);
 		ans%=mod;

 		out.println(ans);

 		out.close();
 	}
	public static long[][] mul(long[][] m1, long[][] m2){
		long[][] ans = new long[y+1][y+1];
		for(int j =0;j<=y;j++){
			for(int k = 0;k<=y;k++){
				for(int l = 0;l<=y;l++){
					ans[j][l]+=m1[j][k]*m2[k][l];
					ans[j][l]%=mod;
				}
			}
		}
		return ans;
	}
	public static long[][] power(long[][] m1, long k){

		if (k == 0){
			long[][] mst = new long[y+1][y+1];
			for(int j =0 ;j<=y;j++){
				mst[j][j] = 1L;
			}
			return mst;
		}

		if (k == 1)
			return m1;
		long [][]ks = power(m1, k/2L);
		if (k%2 == 0)
			return mul(ks, ks);
		else
			return mul(mul(ks, ks), m1);
	}
	public static void sort(int[] array){
		ArrayList<Integer> copy = new ArrayList<Integer>();
		for (int i : array)
			copy.add(i);
		Collections.sort(copy);
		for(int i = 0;i<array.length;i++)
			array[i] = copy.get(i);
	}
	static String[] readArrayString(int n){
		String[] array = new String[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.next();
		return array;
	}
	static int[] readArrayInt(int n){
    	int[] array = new int[n];
    	for(int j = 0;j<n;j++)
    		array[j] = sc.nextInt();
    	return array;
    }
	static int[] readArrayInt1(int n){
		int[] array = new int[n+1];
		for(int j = 1;j<=n;j++){
			array[j] = sc.nextInt();
		}
		return array;
	}
	static long[] readArrayLong(int n){
		long[] array = new long[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.nextLong();
		return array;
	}
	static double[] readArrayDouble(int n){
		double[] array = new double[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.nextDouble();
		return array;
	}
	static int minIndex(int[] array){
		int minValue = Integer.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static int minIndex(long[] array){
		long minValue = Long.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static int minIndex(double[] array){
		double minValue = Double.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static long power(long x, long y){
		if (y == 0)
			return 1;
		if (y%2 == 1)
			return (x*power(x, y-1))%mod;
		return power((x*x)%mod, y/2)%mod;
	}
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is


import java.util.*;
import java.io.*;

public class Sol{
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static FastReader in=new FastReader(inputStream);
static PrintWriter out=new PrintWriter(outputStream);

static class FastReader
{
  BufferedReader br;
  StringTokenizer st;

  public FastReader(InputStream in)
  {
      br = new BufferedReader(new
               InputStreamReader(System.in));
  }

  public String next()
  {
      while (st == null || !st.hasMoreElements())
      {
          try
          {
              st = new StringTokenizer(br.readLine());
          }
          catch (IOException  e)
          {
              e.printStackTrace();
          }
      }
      return st.nextToken();
  }

  public int nextInt()
  {
      return Integer.parseInt(next());
  }

  public long nextLong()
  {
      return Long.parseLong(next());
  }

 public  double nextDouble()
  {
      return Double.parseDouble(next());
  }

  String nextLine()
  {
      String str = "";
      try
      {
          str = br.readLine();
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
      return str;
  }
}

//----------------------------------------------------------------------------------------------//

//----------------S  T  A  R  T  ---------------------------------------------------------------//

//----------------------------------------------------------------------------------------------//

/*linear sieve nlogn
int n=(int)Math.pow(10,6)+100;
long mod=998244353;
long d[]=new long[n];

for(int i=1;i<n;i++){ for(int j=i; j<n; j+=i){ d[j] += 1; }}

long pre[]=new long[n];

pre[1]=1;d[1]=1;
for(int i=2;i<n;i++){d[i]+=pre[i-1]%mod;pre[i] += (pre[i-1]+d[i])%mod;}*/

static class Pair {
        int id;long val;
        public Pair(int id,long val) {

          this.id=id;
         this.val=val;
        }

      }

/*----------nCx---------------
long Comb[][]=new long[61][61];

for(int i=1;i<=60;i++){Comb[i][0]=1;}
for(int i=1;i<=60;i++){Comb[i][1]=i;Comb[i][i]=1;}
for(int i=2;i<=60;i++){for(int j=1;j<i;j++){Comb[i][j]=Comb[i-1][j]+Comb[i-1][j-1];}}
----------nCx------------------
*/

/*----------DFS-------------
static void DFS(int v,int p){
dp[0][v]=0;dp[1][v]=0;
for(int u:adj[v]){
if(u==p)continue;
DFS(u,v);
dp[0][v]+=Math.max(Math.abs(A[0][u]-A[0][v]) + dp[0][u], Math.abs(A[1][u]-A[0][v]) + dp[1][u] );
dp[1][v]+=Math.max(Math.abs(A[0][u]-A[1][v]) + dp[0][u], Math.abs(A[1][u]-A[1][v]) + dp[1][u] );
}

}

static int N=(int)Math.pow(10,5)+10;
static ArrayList<Integer> adj[]=new ArrayList[N];
static long dp[][]=new long[2][N];
static long A[][]=new long[2][N];

-----------DFS--------------
*/
/*static class Edge implements Comparable<Edge>{
int destination;long cost;
Edge(int destination,long cost){this.cost=cost;this.destination=destination;}

@Override

		public int compareTo(Edge o) {
			return Long.compare(cost, o.cost);
		}
}

*/

public static void main(String []args){

int t=1;

while(t-->0){
int n=in.nextInt();int m=in.nextInt();

HashMap<Integer,Integer> hs=new HashMap<>();boolean ans=true;
while(n>0&&ans){int c=n%m;n/=m;int count = hs.getOrDefault(c,0);if(count>0)ans=false;else{hs.put(c,1);}}
if(ans)out.println("YES");
else{out.println("NO");}
 }

out.close();
}}


import java.lang.*;
import java.io.*;
import java.util.ArrayList;
import java.util.PriorityQueue;

/* Name of the class has to be "Main" only if the class is public. */
public class Compilation {

    public static void main(String[] args) throws java.lang.Exception {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String arr[];

        arr = br.readLine().split(" ");
        int n = Integer.parseInt(arr[0]);
        int k = Integer.parseInt(arr[1]);

        int res = k;

        if (n < k) {
            System.out.println(k);
        } else if (n > k) {
            int mod = n % k;
            if ((n / k) * k >= n) {
                System.out.println(n + mod + k);
            } else {
                System.out.println(n - mod + k);
            }
        } else {
            System.out.println(k * 2);
        }

        //while (res <= n) {
        //          res += k;
        //   }
        //      System.out.println(res);
    }
}


import java.io.BufferedReader;
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
public class Vanya_and_Books
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	static void pn(Object o)
	{
		out.println(o);
		out.flush();

	}
	static void p(Object o)
	{
		out.print(o);
		out.flush();
	}
	static void pni(Object o)
	{
		out.println(o);System.out.flush();
	}

	static int I() throws IOException
	{
		return sc.nextInt();
	}
	static long L()throws IOException
	{
		return sc.nextLong();
	}
	static double D()throws IOException
	{
		return sc.nextDouble();
	}
	static String S()throws IOException
	{
		return sc.next();
	}
	static char C() throws IOException
	{
		return sc.next().charAt(0);
	}
	static int countDigits(long n)
	{
		int c=0;
		while(n>0)
		{
			c++;
			n=n/10;
		}

		return c;

	}
	 static int next(long[] arr, long target)
		{
			int start = 0, end = arr.length - 1;

			int ans = -1;
			while (start <= end) {
				int mid = (start + end) / 2;

				// Move to right side if target is
				// greater.
				if (arr[mid] <= target) {
					start = mid + 1;
				}

				// Move left side.
				else {
					ans = mid;
					end = mid - 1;
				}
			}
			return ans;
		}
	public static void process() throws IOException
	{

	    long n=L();
	    if(n<=9)
	    {
	    	pn(n);
	    }
	    else
	    {
		long a1[]= {9,99,999,9999,99999,999999,9999999,99999999,999999999};
		long count[]=new long[9];count[0]=9;
		for(int i1=1;i1<9;i1++)
		{
			count[i1]=a1[i1]-a1[i1-1];
			int ctr=countDigits(a1[i1]);
			count[i1]=count[i1]*ctr;

		}
		for(int i=1;i<9;i++)
		{
			count[i]=count[i]+count[i-1];

		}

		int l=next(a1,n);
		if(l!=-1 && l!=0)
		{
		l=l-1;
	    pn((countDigits(n)*(n-a1[l]))+count[l]);
		}
		else
		if(l==-1)
		{
			l=8;
			pn((countDigits(n)*(n-a1[l]))+count[l]);

		}

	    }

	}
public static void main(String[] args) throws IOException {

	process();
}

}


import java.util.*;
import java.io.*;
public class One {

    public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader( System.in));
int n=Integer.parseInt(br.readLine());
String [] parts= br.readLine().split(" ");
int[] a= new int[n+1];
for(int i=0;i<n;i++){
    a[i]=Integer.parseInt(parts[i]);

}
a[n]=0;
int counter=0;
int start=1;
for(int i=0;i<n;i++){

     if (start==2 && a[i]==0 && a[i+1]==0)
    {i++; start=1; continue;}
else if(a[i]==0 && start==1)
        continue;
    else if(start==1)
    {
        start=2;
        counter++;

    }

    else counter++;

}

System.out.println(counter);
br.close();
}//end of main function

}//end of Main class


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_245_Div1 {

    public static long MOD = 1000000007;
    static int[] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int[] data = new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();
        }
        Arrays.sort(data);

        if (data[n - 1] == n && data[0] == 1) {
            dp = new int[1 << n];
            boolean v = cal(0, 0, data);
            if (v) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        } else {
            out.println("NO");
        }
        out.close();
    }

    static boolean cal(int index, int mask, int[] data) {
        if (index == data.length) {
            return Integer.bitCount(mask) == 1;
        }
        // System.out.println(index + " " + Integer.toBinaryString(mask));
        int num = (index + 1) * mask;
        int x = num / 30;
        int y = num % 30;
        if ((dp[x] & (1 << y)) != 0) {
            return false;
        }
        dp[x] |= (1 << y);
        if (data[index] == 1) {
            return cal(index + 1, mask | (1 << index), data);
        } else {

            for (int i = mask;; i = (i - 1) & mask) {

                if (Integer.bitCount(i) > 1) {
                    int sum = 0;
                    for (int j = 0; j < data.length; j++) {
                        if (((1 << j) & i) != 0) {
                            sum += data[j];
                        }
                    }
                    // System.out.println(sum + " " + data[index] + " " + Integer.bitCount(mask));
                    if (sum + 1 == data[index]) {
                        if (cal(index + 1, (mask ^ i) | (1 << index), data)) {
                            return true;
                        }
                    }
                }

                if (i == 0) {
                    break;
                }
            }
            return false;
        }

    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.*;
import java.io.*;

public class Main {

	int solve(Scanner in, PrintWriter out)
	{
		int n = in.nextInt();
		int[] arr = new int[n];

		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();

		if(n == 2)
			out.print(arr[1] + (arr[1] - arr[0]));
		else{
			int ans = 0;
			int step = arr[0] - arr[1];
			for(int i = 0; i < n-1; i++){
				if((arr[i] - arr[i+1]) == step)
					ans = arr[n-1] +(arr[1] - arr[0]);
				else{
					ans = arr[n - 1];
					break;
				}
			}
			out.print(ans);
		}

			return 0;

	}

	void run()
	{
		try(
			Scanner in = new Scanner(System.in);
			PrintWriter out = new PrintWriter(System.out)) {

			solve(in, out);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

}


import java.util.Scanner;

public class TestClass {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int n = in.nextInt();
        int s = in.nextInt();
        int p = in.nextInt();
        int ans = (int)Math.ceil((double)(k * (int)Math.ceil((double)n/s)) / p);
        System.out.println(ans);
    }
}


//package codeforces.cp541;

import java.util.Scanner;

public class A {

	public static void getFourthSet(char[][] mB,String[] matrixB) {
		for (int i = mB.length-1; i >= 0; i--) {
			String temp = "";
			for (int j = mB.length - 1; j >= 0; j--) {
				temp += (mB[j][i] + "");
			}
			matrixB[6] += temp;
			matrixB[7] += new StringBuilder(temp).reverse();
		}
	}

	public static void getThirdSet(char[][] mB, String[] matrixB) {
		for (int i = 0; i < mB.length; i++) {
			String temp = "";
			for (int j = mB.length - 1; j >= 0; j--) {
				temp += (mB[j][i] + "");
			}
			matrixB[4] += temp;
			matrixB[5] += new StringBuilder(temp).reverse();
		}
	}

	public static void getSecondSet(char[][] mB, String[] matrixB) {
		for (int i = mB.length - 1; i >= 0; i--) {
			String temp = "";
			for (int j = 0; j < mB.length; j++) {
				temp += (mB[i][j] + "");
			}
			matrixB[2] += temp;
			matrixB[3] += new StringBuilder(temp).reverse();
		}
	}

	public static void getFirstSet(char[][] mB, String[] matrixB) {
		for (int i = 0; i < mB.length; i++) {
			String temp = "";
			for (int j = 0; j < mB.length; j++) {
				temp += (mB[i][j] + "");
			}
			matrixB[0] += temp;
			matrixB[1] += new StringBuilder(temp).reverse();
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		char[][] mB = new char[n][n];
		String matrixA = "";
		String[] matrixB = new String[8];
		for (int i = 0; i < n; i++)
			matrixA += in.next();
		//System.out.println(matrixA);
		for(int i=0;i<8;i++)
			matrixB[i] = "";
		for (int i = 0; i < n; i++)
			mB[i] = in.next().toCharArray();
		getFirstSet(mB, matrixB);
		//System.out.println("0 : "+matrixB[0]);
		//System.out.println("1 : "+matrixB[1]);
		if (matrixB[0].equals(matrixA) || matrixB[1].equals(matrixA)) {
			System.out.println("Yes");
		} else {
			getSecondSet(mB, matrixB);
			//System.out.println("2 : "+matrixB[2]);
			//System.out.println("3 : "+matrixB[3]);
			if (matrixB[2].equals(matrixA) || matrixB[3].equals(matrixA)) {
				System.out.println("Yes");
			} else {
				getThirdSet(mB, matrixB);
				//System.out.println("4 : "+matrixB[4]);
				//System.out.println("5 : "+matrixB[5]);
				if (matrixB[4].equals(matrixA) || matrixB[5].equals(matrixA)) {
					System.out.println("Yes");
				} else {
					getFourthSet(mB, matrixB);
					if (matrixB[6].equals(matrixA) || matrixB[7].equals(matrixA)) {
						System.out.println("Yes");
					} else {
						System.out.println("No");
					}
				}
			}

		}
		in.close();
	}
}


import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] arg){
    Scanner in = new Scanner(System.in);
      try (PrintWriter out = new PrintWriter(System.out)) {
          int p1 = in.nextInt();
          int p2 = in.nextInt();
          int v1 = in.nextInt();
          int v2 = in.nextInt();
          if (Math.max(v1, v2) >= (p2 + p1) || (v1 >= p1 && v2 >= p2)) {

              out.println("Polycarp");
          }
          else{
              out.println("Vasiliy");
          }
      }
  }
}


import java.util.*;
import java.io.*;

public class Olimp {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        long x=in.nextLong();
        long y=in.nextLong();
        if(x>0 && y>0) System.out.println(0+" "+(x+y)+" "+(x+y)+" "+0);
        else if(x<0 && y>0) System.out.println((x-y)+" "+0+" "+0+" "+(-x+y));
        else if(x<0 && y<0) System.out.println((x+y)+" "+0+" "+0+" "+(x+y));
        else if(x>0 && y<0) System.out.println(0+" "+(-x+y)+" "+(x-y)+" "+0);
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

   int d[][] = new int[301][301];
   final int L = 1;
   final int NV = 0;
   final int W = 2;

   private void solve() throws IOException {
      int n = ni();
      int a[] = nia(n);

      if (n == 1) {
         if (a[0] == 0) {
            s();
         } else {
            f();
         }

         return;
      }

      if (n == 3) {
         if ((a[0] ^ a[1] ^ a[2]) == 0) {
            s();
         } else
            f();
         return;
      }

      if (go(a[0], a[1]) == W) {
         f();
      } else
         s();
   }

   private int go(int a, int b) {
      if (d[a][b] != NV)
         return d[a][b];

      for (int i = 1; i <= a; ++i) {
         if (go(a - i, b) == L)
            return d[a][b] = W;
      }

      for (int i = 1; i <= b; ++i) {
         if (go(a, b - i) == L)
            return d[a][b] = W;
      }

      for (int i = 1; i <= Math.min(a, b); ++i) {
         if (go(a - i, b - i) == L)
            return d[a][b] = W;
      }

      return d[a][b] = L;
   }

   private void s() {
      prln("BitAryo");
   }

   private void f() {
      prln("BitLGM");
   }

   /*
    * private void solve() throws IOException { int n = nextInt(); long a[] =
    * nextLongArray(n);
    *
    * long pref[] = new long[n + 1]; long suff[] = new long[n + 1];
    *
    * pref[0] = 0; suff[n] = 0;
    *
    * long xor = 0; for (int i = 1; i <= n; ++i) { xor = xor ^ a[i - 1]; pref[i]
    * = xor; }
    *
    * xor = 0; for (int i = n - 1; i >= 0; --i) { xor = xor ^ a[i]; if (xor >
    * suff[i + 1]) suff[i] = xor; else suff[i] = suff[i + 1]; }
    *
    * long plesure = 0; for (int i = 0; i <= n; ++i) { if ((pref[i] ^ suff[i]) >
    * plesure) plesure = pref[i] + suff[i]; }
    *
    * println(plesure); }
    */

   /*
    * private void qsort(int a[]) { Random rand = new Random(271828182l);
    * qsort(a, 0, a.length, rand); }
    *
    * private void qsort(int a[], int l, int r, Random rand) { if (r - l <= 1)
    * return;
    *
    * int x = a[rand.nextInt(r - l) + l]; int i = l, j = r - 1; while (i < j) {
    * while (a[i] < x) ++i; while (a[j] > x) --j; if (i < j) { int t = a[i];
    * a[i] = a[j]; a[j] = t; ++i; --j; } }
    *
    * qsort(a, l, i, rand); qsort(a, j + 1, r, rand); }
    */

   private int[] nia(int n) throws IOException {
      int arr[] = new int[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Integer.parseInt(nextToken());
      return arr;
   }

   private long[] nla(int n) throws IOException {
      long arr[] = new long[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Long.parseLong(nextToken());
      return arr;
   }

   public static void main(String[] args) {
      new Main().run();
   }

   public void run() {
      try {
         if (isFileIO) {
            pw = new PrintWriter(new File("output.out"));
            br = new BufferedReader(new FileReader("input.in"));
         } else {
            pw = new PrintWriter(System.out);
            br = new BufferedReader(new InputStreamReader(System.in));
         }
         solve();
         pw.close();
         br.close();
      } catch (IOException e) {
         System.err.println("IO Error");
      }
   }

   private void pr(Object o) {
      pw.print(o);
   }

   private void prln(Object o) {
      pw.println(o);
   }

   private void prln() {
      pw.println();
   }

   int ni() throws IOException {
      return Integer.parseInt(nextToken());
   }

   long nl() throws IOException {
      return Long.parseLong(nextToken());
   }

   double nd() throws IOException {
      return Double.parseDouble(nextToken());
   }

   private String nextToken() throws IOException {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
         tokenizer = new StringTokenizer(br.readLine());
      }

      return tokenizer.nextToken();
   }

   private BufferedReader br;
   private StringTokenizer tokenizer;
   private PrintWriter pw;
   private final boolean isFileIO = false;
}


import java.util.Scanner;
public class littel_arthem {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int no = sc.nextInt();
        int row = 0;
        int col = 0;
        if(no == 1)
        {
            System.out.println("1 1");
        }
        else if(no == 2)
        {
            System.out.println("1 2");
        }
        else if(no == 3)
        {
            System.out.println("1 3");
        }
        else
        {
            for(int i=(int)Math.sqrt(no);i>=1;i--)
            {
                if(no%i==0)
                {
                    row = i;
                    col = no/i;
                    break;
                }
            }
            System.out.println(row+" "+col);
        }

    }
}


import java.util.*;

public class chess {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<Integer> a=new ArrayList<Integer>();
		for(int i=0;i<n/2;i++){
			int t=sc.nextInt();
			a.add(t);
		}
		Collections.sort(a);
		int ans1=0;
		int ans2=0;
		int x=n;
		for(int i=n/2-1;i>=0;i--){
			ans1+=Math.abs(x-a.get(i));
			ans2+=Math.abs(x-1-a.get(i));
			x=x-2;
		}
		System.out.println(Math.min(ans1, ans2));

	}

}