Iahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n). Iahub can go from one cell (i, j) only down or right, that is to cells (i + 1, j) or (i, j + 1). 

Also, there are m cells that are occupied by volcanoes, which Iahub cannot enter. 

Iahub is initially at cell (1, 1) and he needs to travel to cell (n, n). Knowing that Iahub needs 1 second to travel from one cell to another, find the minimum time in which he can arrive in cell (n, n).

Input

The first line contains two integers n (1 ≤ n ≤ 109) and m (1 ≤ m ≤ 105). Each of the next m lines contains a pair of integers, x and y (1 ≤ x, y ≤ n), representing the coordinates of the volcanoes.

Consider matrix rows are numbered from 1 to n from top to bottom, and matrix columns are numbered from 1 to n from left to right. There is no volcano in cell (1, 1). No two volcanoes occupy the same location. 

Output

Print one integer, the minimum time in which Iahub can arrive at cell (n, n). If no solution exists (there is no path to the final cell), print -1.

Examples

Input

4 2
1 3
1 4


Output

6


Input

7 8
1 6
2 6
3 5
3 6
4 3
5 1
5 2
5 3


Output

12


Input

2 2
1 2
2 1


Output

-1

Note

Consider the first sample. A possible road is: (1, 1) →  (1, 2) →  (2, 2) →  (2, 3) →  (3, 3) →  (3, 4) →  (4, 4).
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Collection;
import java.io.IOException;
import java.util.NavigableMap;
import java.util.stream.Collectors;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.AbstractMap;
import java.util.stream.Stream;
import java.util.TreeMap;
import java.io.Closeable;
import java.io.Writer;
import java.util.Map.Entry;
import java.util.Comparator;
import java.util.Collections;
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 << 29);
        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);
            BVolcanoes solver = new BVolcanoes();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class BVolcanoes {
        int inf = (int) 1e9 + 10;

        public int nextActive(TreeMap<Integer, Interval> map, int key) {
            Interval floor = CollectionUtils.floorValue(map, key);
            if (floor != null && floor.r >= key) {
                return key;
            }
            Interval ceil = CollectionUtils.ceilValue(map, key);
            if (ceil != null) {
                return ceil.l;
            }
            return inf;
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.ri();
            int m = in.ri();
            TreeMap<Integer, Interval> map = new TreeMap<>();
            List<int[]> obstacles = new ArrayList<>(m);
            for (int i = 0; i < m; i++) {
                obstacles.add(new int[]{in.ri(), in.ri()});
            }
            map.put(1, new Interval(1, 1));
            obstacles.sort(Comparator.comparingInt(x -> x[1]));
            Map<Integer, List<int[]>> group = obstacles.stream().collect(Collectors.groupingBy(x -> x[0]));
            TreeSet<Integer> set = new TreeSet<>();
            set.add(1);
            for (Integer key : group.keySet()) {
                set.add(key);
                if (key + 1 <= n) {
                    set.add(key + 1);
                }
            }


            for (Integer key : set) {
                if (map.isEmpty()) {
                    break;
                }
                List<int[]> obstacle = group.getOrDefault(key, Collections.emptyList());
                TreeMap<Integer, Interval> next = new TreeMap<>();
                int last = 0;
                for (int[] x : obstacle) {
                    int cur = x[1];
                    int begin = nextActive(map, last + 1);
                    if (begin < cur) {
                        next.put(begin, new Interval(begin, cur - 1));
                    }
                    last = cur;
                }

                int cur = n + 1;
                int begin = nextActive(map, last + 1);
                if (begin < cur) {
                    next.put(begin, new Interval(begin, cur - 1));
                }

                map = next;
            }

            boolean possible = nextActive(map, n) == n;
            out.println(possible ? 2 * n - 2 : -1);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 32 << 10;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        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;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

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

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

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

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

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append('\n');
        }

        public FastOutput flush() {
            try {
//            boolean success = false;
//            if (stringBuilderValueField != null) {
//                try {
//                    char[] value = (char[]) stringBuilderValueField.get(cache);
//                    os.write(value, 0, cache.length());
//                    success = true;
//                } catch (Exception e) {
//                }
//            }
//            if (!success) {
                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 CollectionUtils {
        public static <K, V> V floorValue(NavigableMap<K, V> map, K key) {
            Map.Entry<K, V> entry = map.floorEntry(key);
            return entry == null ? null : entry.getValue();
        }

        public static <K, V> V ceilValue(NavigableMap<K, V> map, K key) {
            Map.Entry<K, V> entry = map.ceilingEntry(key);
            return entry == null ? null : entry.getValue();
        }

    }

    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 int ri() {
            return readInt();
        }

        public int readInt() {
            int sign = 1;

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

            int 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 class Interval {
        int l;
        int r;

        public Interval(int l, int r) {
            this.l = l;
            this.r = r;
        }

    }
}

