Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.

Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). The second line contains m integers a1, a2, ..., am (1 ≤ ai ≤ n). Note that Xenia can have multiple consecutive tasks in one house.

Output

Print a single integer — the time Xenia needs to complete all tasks.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

4 3
3 2 3


Output

6


Input

4 3
2 3 3


Output

2

Note

In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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

public class cf339b {
    
    static BufferedReader br;
    static Scanner sc;
    static PrintWriter out;
    
    public static void initA() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            sc = new Scanner(System.in);
            out = new PrintWriter(System.out);
        } catch (Exception e) {
        }
    }

    static boolean next_permutation(Integer[] p) {
        for (int a = p.length - 2; a >= 0; --a) {
            if (p[a] < p[a + 1]) {
                for (int b = p.length - 1;; --b) {
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
                }
            }
        }
        return false;
    }
    
    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }
    
    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }
    
    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }
    
    public static Long[] getLongArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Long temp2[] = new Long[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Long.parseLong(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }
    
    public static String[] getStringArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            String temp2[] = new String[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = (temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }
    
    public static void print(Object a) {
        out.println(a);
    }
    
    public static void print(String s, Object... a) {
        out.printf(s, a);
    }
    
    public static int nextInt() {
        return sc.nextInt();
    }
    
    public static double nextDouble() {
        return sc.nextDouble();
    }
    
    public static void main(String[] ar) {
        initA();
        solve();
        out.flush();
    }
    
    public static void solve() {
        Long in[] = getLongArr();
        long n = in[0], m = in[1];
        
        Integer data[] = getIntArr();
        for(int i =0 ;i<m;i++){
            data[i]--;
        }
        long out =0 ;
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i =0 ;i<m;i++){
            list.add(i);
        }
        int cur_pos =0 , cur_job = 0;
        while(cur_job<m){
            int next_pos = data[cur_job];
            
            if(next_pos >= cur_pos){
                out+= next_pos - cur_pos;
            }else{
                out+=n-cur_pos + next_pos;
            }
            
            cur_job++;
            cur_pos = next_pos;
            //print("POSISI SKR "+(cur_pos+1));
        }
        print(out);
        
    }
}
