Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Output

Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.

Examples

Input

10


Output

10


Input

123


Output

113

Note

In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author GYSHGX868
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private int n;
        private LongSet set = new LongTreeSet();

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            for (int i = 0; i <= 9; i++) {
                for (int j = i + 1; j <= 9; j++) {
                    find(i, j, 0);
                }
            }
            out.printLine(set.size());
        }

        private void find(int x, int y, long cur) {
            long getx = cur * 10 + x;
            long gety = cur * 10 + y;
            if (getx != 0 && getx <= n) {
                set.add(getx);
                find(x, y, getx);
            }
            if (gety <= n) {
                set.add(gety);
                find(x, y, gety);
            }
        }

    }

    static interface LongStream extends Iterable<Long>, Comparable<LongStream> {
        public LongIterator longIterator();


        public default Iterator<Long> iterator() {
            return new Iterator<Long>() {
                private LongIterator it = longIterator();


                public boolean hasNext() {
                    return it.isValid();
                }


                public Long next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    long result = it.value();
                    it.advance();
                    return result;
                }
            };
        }


        public default int compareTo(LongStream c) {
            LongIterator it = longIterator();
            LongIterator jt = c.longIterator();
            while (it.isValid() && jt.isValid()) {
                long i = it.value();
                long j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }

    static interface LongSet extends LongCollection {
    }

    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 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 static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }

    static interface LongIterator {
        public long value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static interface LongComparator {
        public static final LongComparator DEFAULT = (first, second) -> {
            if (first < second) {
                return -1;
            }
            if (first > second) {
                return 1;
            }
            return 0;
        };

        public int compare(long first, long second);

    }

    static class LongTreeSet implements LongSet {
        private final LongComparator comparator;
        private LongTreeSet.Entry root;
        private int size = 0;
        private transient int modCount = 0;
        private static final boolean RED = false;
        private static final boolean BLACK = true;

        public LongTreeSet() {
            comparator = LongComparator.DEFAULT;
        }

        public LongTreeSet(LongComparator comparator) {
            this.comparator = comparator;
        }


        public int size() {
            return size;
        }


        public LongIterator longIterator() {
            return null;
        }


        public void add(long key) {
            LongTreeSet.Entry t = root;
            if (t == null) {
                compare(key, key);

                root = new LongTreeSet.Entry(key, null);
                size = 1;
                modCount++;
                return;
            }
            int cmp;
            LongTreeSet.Entry parent;
            LongComparator cpr = comparator;

            do {
                parent = t;
                cmp = cpr.compare(key, t.key);
                if (cmp < 0)
                    t = t.left;
                else if (cmp > 0)
                    t = t.right;
                else
                    return;
            } while (t != null);

            LongTreeSet.Entry e = new LongTreeSet.Entry(key, parent);
            if (cmp < 0)
                parent.left = e;
            else
                parent.right = e;
            fixAfterInsertion(e);
            size++;
            modCount++;
        }

        @SuppressWarnings("unchecked")
        final int compare(long k1, long k2) {
            return comparator.compare(k1, k2);
        }

        private static <K, V> boolean colorOf(LongTreeSet.Entry p) {
            return (p == null ? BLACK : p.color);
        }

        private static <K, V> LongTreeSet.Entry parentOf(LongTreeSet.Entry p) {
            return (p == null ? null : p.parent);
        }

        private static <K, V> void setColor(LongTreeSet.Entry p, boolean c) {
            if (p != null)
                p.color = c;
        }

        private static <K, V> LongTreeSet.Entry leftOf(LongTreeSet.Entry p) {
            return (p == null) ? null : p.left;
        }

        private static <K, V> LongTreeSet.Entry rightOf(LongTreeSet.Entry p) {
            return (p == null) ? null : p.right;
        }

        private void rotateLeft(LongTreeSet.Entry p) {
            if (p != null) {
                LongTreeSet.Entry r = p.right;
                p.right = r.left;
                if (r.left != null)
                    r.left.parent = p;
                r.parent = p.parent;
                if (p.parent == null)
                    root = r;
                else if (p.parent.left == p)
                    p.parent.left = r;
                else
                    p.parent.right = r;
                r.left = p;
                p.parent = r;
            }
        }

        private void rotateRight(LongTreeSet.Entry p) {
            if (p != null) {
                LongTreeSet.Entry l = p.left;
                p.left = l.right;
                if (l.right != null) l.right.parent = p;
                l.parent = p.parent;
                if (p.parent == null)
                    root = l;
                else if (p.parent.right == p)
                    p.parent.right = l;
                else p.parent.left = l;
                l.right = p;
                p.parent = l;
            }
        }

        private void fixAfterInsertion(LongTreeSet.Entry x) {
            x.color = RED;
            while (x != null && x != root && x.parent.color == RED) {
                if (parentOf(x) == leftOf(parentOf(parentOf(x)))) {
                    LongTreeSet.Entry y = rightOf(parentOf(parentOf(x)));
                    if (colorOf(y) == RED) {
                        setColor(parentOf(x), BLACK);
                        setColor(y, BLACK);
                        setColor(parentOf(parentOf(x)), RED);
                        x = parentOf(parentOf(x));
                    } else {
                        if (x == rightOf(parentOf(x))) {
                            x = parentOf(x);
                            rotateLeft(x);
                        }
                        setColor(parentOf(x), BLACK);
                        setColor(parentOf(parentOf(x)), RED);
                        rotateRight(parentOf(parentOf(x)));
                    }
                } else {
                    LongTreeSet.Entry y = leftOf(parentOf(parentOf(x)));
                    if (colorOf(y) == RED) {
                        setColor(parentOf(x), BLACK);
                        setColor(y, BLACK);
                        setColor(parentOf(parentOf(x)), RED);
                        x = parentOf(parentOf(x));
                    } else {
                        if (x == leftOf(parentOf(x))) {
                            x = parentOf(x);
                            rotateRight(x);
                        }
                        setColor(parentOf(x), BLACK);
                        setColor(parentOf(parentOf(x)), RED);
                        rotateLeft(parentOf(parentOf(x)));
                    }
                }
            }
            root.color = BLACK;
        }

        static final class Entry {
            long key;
            LongTreeSet.Entry left;
            LongTreeSet.Entry right;
            LongTreeSet.Entry parent;
            boolean color = BLACK;

            Entry(long key, LongTreeSet.Entry parent) {
                this.key = key;
                this.parent = parent;
            }

        }

    }

    static interface LongCollection extends LongStream {
        public int size();

        public default void add(long value) {
            throw new UnsupportedOperationException();
        }

    }

    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 printLine(int i) {
            writer.println(i);
        }

    }
}


			  	   	 	  	  				  			