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

public class Main
{
    static final long mod=(int)1e9+7;
    public static void main(String[] args) throws Exception
    {
    	FastReader in=new FastReader();
    	PrintWriter pw=new PrintWriter(System.out);
    	int n=in.nextInt();
    	long ans=0;
    	for(int i=2;2*i<=n;i++)
    	{
    		ans+=i*(n/i-1);
    	}
    	ans*=4;
    	pw.print(ans);
    	pw.flush();
    }
}

class pair
{
	int f,s;
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

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

    public String next() throws IOException
    {
        if(st==null || !st.hasMoreElements())
        {
            st=new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

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


import java.io.*;
import java.util.*;
public class D1062
{
    public static void main(String args[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n<=3)
            System.out.println(0);
        else
        {
            long sum=0;
            for(int i=2;i<=n/2;i++)
            {
                long t=n/i;
                long p=t*(t+1);
                p=p/2;
                p--;
                sum=sum+(p*4);
            }
            System.out.println(sum);
        }
    }
}


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

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

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		out.println(work());
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}

	//12+8+16+12+8+8
	long ret=0;
	long work() {
		int n=in.nextInt();
		long ret=0;
		for(int i=n;i>=4;i--) {
			int v=(int)Math.sqrt(i);
			for(int j=v;j>=2;j--) {
				if(i%j==0) {
					ret+=4*(i/j);
					if(i/j!=j) {
						ret+=4*j;
					}
				}
			}
		}
		return ret;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

	public String next()
	{
		if(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());
	}
}


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

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

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		out.println(work());
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	long ret=0;
	long work() {
		int n=in.nextInt();
		long ret=0;
		for(int i=n;i>=4;i--) {
			int v=(int)Math.sqrt(i);
			for(int j=v;j>=2;j--) {
				if(i%v==0) {
					ret+=4*(i/v);
					if(i/v!=v) {
						ret+=4*v;
					}
				}
			}
		}
		return ret;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

	public String next()
	{
		if(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());
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.util.Arrays;

public class D {

    static int[] primes;
    static int[] spf;

    static long[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sieve(n);

        dp = new long[n + 1];

        for (int i = 2; i <= n; i++){
            if (primes[i] == 0) {
                dp[i] = i + 1;
            }
            else {
                int j = i;
                while (j % spf[i] == 0) {
                    j = j / spf[i];
                }
                if (j == 1) {
                    dp[i] = dp[i/spf[i]] * spf[i] + 1;
                } else {
                    dp[i] = dp[j] * dp[i/j];
                }
            }
        }

//        System.out.println(Arrays.toString(dp));

        long ans = 0;
        for (int i = n; i >= 2; i--) {
            if (primes[i] == 0) {
            } else {
                ans += 4 * (dp[i] - i - 1);
            }
        }

        System.out.println(ans);
    }

    static void sieve(int n) {
        primes = new int[n+1];
        spf = new int[n+1];
        int leastUnmarked = 2;
        while (leastUnmarked <= n) {
            for (int i = 2; i <= n / leastUnmarked; i++) {
                if (primes[i * leastUnmarked] == 0) {
                    primes[i * leastUnmarked] = -1; spf[i * leastUnmarked] = leastUnmarked;
                }
            }
            leastUnmarked++;
            while (leastUnmarked <= n && primes[leastUnmarked] == -1) leastUnmarked++;
        }
    }

}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.util.Arrays;

public class D {

    static int[] primes;
    static int[] spf;

    static long[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sieve(n);

        dp = new long[n + 1];

        for (int i = 2; i <= n; i++){
            if (primes[i] == 0) {
                dp[i] = i + 1;
            }
            else {
                int j = i;
                while (j % spf[i] == 0) {
                    j = j / spf[i];
                }
                if (j == 1) {
                    dp[i] = dp[i/spf[i]] * spf[i] + 1;
                } else {
                    dp[i] = dp[j] * dp[i/j];
                }
            }
        }

//        System.out.println(Arrays.toString(dp));

        int ans = 0;
        for (int i = n; i >= 2; i--) {
            if (primes[i] == 0) {
            } else {
                ans += 4 * (dp[i] - i - 1);
            }
        }

        System.out.println(ans);
    }

    static void sieve(int n) {
        primes = new int[n+1];
        spf = new int[n+1];
        int leastUnmarked = 2;
        while (leastUnmarked <= n) {
            for (int i = 2; i <= n / leastUnmarked; i++) {
                if (primes[i * leastUnmarked] == 0) {
                    primes[i * leastUnmarked] = -1; spf[i * leastUnmarked] = leastUnmarked;
                }
            }
            leastUnmarked++;
            while (leastUnmarked <= n && primes[leastUnmarked] == -1) leastUnmarked++;
        }
    }

}


//package que_b;

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

public class utkarsh {

    InputStream is;
    PrintWriter out;

    long mod = (long) (1e9 + 7), inf = (long) (3e18);

    void solve() {
        int n = ni();
        long ans = 0;
        for(int i = 2; i < n; i++) {
            long x = n / i;
            if(x == 1)  break;
            x = x * (x+1) / 2 - 1;
            ans += x;
        }
        out.println(ans << 2);
    }

    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if((e&1) == 1)  r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------

    public static void main(String[] args) { new utkarsh().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}


import java.util.*;
import java.lang.*;

public class d {
    public static final long MOD = (long)1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Locale.setDefault(Locale.US);
        int n = in.nextInt();
        int ans = 0;
        for (int i = 2; i <= n; ++i) {
            for (int j = 2; i * j <= n; ++j) {
                int to = i * j;
                ans += j * 4;
            }
        }
        System.out.print(ans + "\n");
    }
}


import java.util.*;
import java.lang.*;

public class d {
    public static final long MOD = (long)1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Locale.setDefault(Locale.US);
        int n = in.nextInt();
        int ans = 0;
        for (int i = 2; i <= n; ++i) {
            for (int j = 2; i * j <= n; ++j) {
                int to = i * j;
                ans += j * 4;
                for (int k = 2; k * to <= n; ++k) {
                    int nxt = to * k;
                    ans += k * 4;
                }
            }
        }
        System.out.print(ans + "\n");
    }
}


import java.util.*;
import java.lang.*;

public class d {
    public static final long MOD = (long)1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Locale.setDefault(Locale.US);
        long n = in.nextLong();
        long ans = 0;
        for (long i = 2; i <= n; ++i) {
            for (long j = 2; i * j <= n; ++j) {
                long to = i * j;
                ans += j * 4;
            }
        }
        System.out.print(ans + "\n");
    }
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=1;i<=arr[n-1]||c==n;i++)
    {
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=1;i<=arr[n];i++)
    {
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
bool in[3005];
int main()
{
    int n,x,i,max=-1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x>max)max=x;
        in[x]=1;
    }
    for(i=1;i<=max+1;i++)
    {
        if(!in[i]){printf("%d\n",i);return 0;}
    }

    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
bool in[3005];
int main()
{
    int n,x,i;
    scanf("%d",&n);
    int min=1<<30,max=-1;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x<min)min=x;
        if(x>max)max=x;
        in[x]=1;
    }
    for(i=min;i<=max+1;i++)
    {
        if(!in[i]){printf("%d\n",i);return 0;}
    }

    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=1;i<=3001;i++)
    {
        if(c==n)break;
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=arr[0];i<=n;i++)
    {
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=1;i<=n;i++)
    {
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,t;
	cin>>n;
	int a[3001];
	for(int i=0;i<n;cin>>t, a[t]++,i++);
	for(int i=1;i<=3002;++i) if(a[i]==0) {cout<<i<<endl; break;}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,t;
	cin>>n;
	int a[3001];
	for(int i=0;i<n;cin>>t, a[t]++,i++);
	for(int i=1;i<=3001;++i) if(a[i]==0) {cout<<i<<endl; break;}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,t;
	cin>>n;
	int a[3002]={0};
	for(int i=0;i<n;cin>>t, a[t]++,i++);
	for(int i=1;i<=3001;++i) if(a[i]==0) {cout<<i<<endl; break;}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,t;
	cin>>n;
	int a[3001];
	for(int i=0;i<n;cin>>t, a[t]++);
	for(int i=1;i<3001;++i) if(a[i]==0) {cout<<i<<endl; break;}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,t;
	cin>>n;
	int a[3001];
	for(int i=0;i<n;cin>>t, a[t]++,i++);
	for(int i=1;i<3001;++i) if(a[i]==0) {cout<<i<<endl; break;}
	return 0;
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3001] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 0; s < n; s++){
        if (a[s] == 0){
            cout << s + 1 << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3000] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 0; s < n; s++){
        if (a[s] == 0){
            cout << s + 1 << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3002] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 1; s < 3002; s++){
        if (a[s] == 0){
            cout << s << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3001] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 1; s < 3000; s++){
        if (a[s] == 0){
            cout << s + 1 << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int num[3002] = {0};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        num[tmp]++;
    }
    for (int x = 1; x < 3002; x++){
        if (num[x] == 0){
            cout << x << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3001] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 1; s < 3002; s++){
        if (a[s] == 0){
            cout << s + 1 << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int num[3001] = {0};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        num[tmp]++;
    }
    for (int x = 1; x < 3001; x++){
        if (num[x] == 0){
            cout << x << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3001] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 1; s < 3002; s++){
        if (a[s] == 0){
            cout << s << endl;
            break;
        }
    }
}


#include <iostream>

using namespace std;

int main (){
    int n;
    int a[3001] = {0};
    cin >> n;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for (int s = 1; s < n; s++){
        if (a[s] == 0){
            cout << s + 1 << endl;
            break;
        }
    }
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k,g=0;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=3000;i++) if(!a[i]) {cout<<i<<endl;g=1;break;}
if(g) cout<<3001<endl;
return 0;
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k,g=0;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=3000;i++) if(!a[i]) {cout<<i<<endl;g=1;break;}
if(g) cout<<3001;
return 0;
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k,g=0;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=3000;i++) if(!a[i]) {cout<<i;g=1;break;return 0;}
if(!g) cout<<3001;
return 0;
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=n;i++) if(!a[i]) {cout<<i;break;}
return 0;
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=k;i++) if(!a[i]) {cout<<i;break;}
return 0;
}


#include<iostream>
using namespace std;
main()
{ int n,a[3000],i,k;
cin>>n;
for(i=1;i<=n;i++) a[i]=0;
for(i=1;i<=n;i++) {cin>>k;a[k]++;}
for(i=1;i<=3000;i++) if(!a[i]) {cout<<i;break;}
return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
   int x[3001];
   int c, j=0;
   cin >> c;
   for(int i=0; i < c ; i++)
    cin >> x[i];
    sort(x, x+c);
   for(int i=0; i < c; i++){
        if(x[i] !=  j+1){
            cout << j+1;
            return 0;
        }
        else
            j++;
   }
   cout << j+1;
}


#include<iostream>
using namespace std;

int main(){
    bool jack[3001] = { false };
    int x, num, target;
    cin >> x;
    for (int i = 0; i < x; i++){
        cin >> num;
        jack[num] = true;

    }
    for (int i = 1; i < 5000; i++)
    {
        if (jack[i] == false){
            target = i;
            break;
        }

    }

    cout << target;

}


#include<iostream>
using namespace std;

int main(){
    bool jack[3001] = { false };
    int x, num, target;
    cin >> x;
    for (int i = 0; i < x; i++){
        cin >> num;
        jack[num] = true;

    }
    for (int i = 1; i <= 3001; i++)
    {
        if (jack[i] == false){
            target = i;
            break;
        }

    }

    cout << target;

}


#include<iostream>
using namespace std;

int main(){
    bool jack[3002] = { false };
    int x, num, target;
    cin >> x;
    for (int i = 0; i < x; i++){
        cin >> num;
        jack[num] = true;

    }
    for (int i = 1; i < 5000; i++)
    {
        if (jack[i] == false){
            target = i;
            break;
        }

    }

    cout << target;

}


#include<iostream>
using namespace std;

int main(){
    bool jack[3001] = { false };
    int x, num, target;
    cin >> x;
    for (int i = 0; i < x; i++){
        cin >> num;
        jack[num] = true;

    }
    for (int i = 1; i < 3001; i++)
    {
        if (jack[i] == false){
            target = i;
            break;
        }

    }

    cout << target;

}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
   int x[3001];
   int c, j=0;
   cin >> c;
   for(int i=0; i < c ; i++)
    cin >> x[i];
    sort(x, x+c);
   for(int i=0; i < c; i++){
        if(x[i] !=  j+1){
            cout << j+1;
            return 0;
        }
        else
            j++;
   }
}


#include<iostream>
using namespace std;

int main(){
    bool jack[3000] = { false };
    int x, num, target;
    cin >> x;
    for (int i = 0; i < x; i++){
        cin >> num;
        jack[num] = true;

    }
    for (int i = 1; i < 3000; i++)
    {
        if (jack[i] == false){
            target = i;
            break;
        }

    }

    cout << target;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
#include <list>
#include <ctime>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <fstream>

#define MAXN 32

using namespace std;

int main() {
    int n; cin >> n;
    int arr[3001]; int num;
    for(int i = 1; i < n; i++) {
        cin >> num;
        arr[num] = 1;
    }

    for(int i = 1; i <= 3000; i++) {
        if(arr[i] == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
#include <list>
#include <ctime>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <fstream>

#define MAXN 32

using namespace std;

int main() {
    int n; cin >> n;
    int arr[3001] = {0}; int num;
    for(int i = 1; i < n; i++) {
        cin >> num;
        arr[num] = 1;
    }

    for(int i = 1; i <= 3000; i++) {
        if(arr[i] == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
#include <list>
#include <ctime>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <fstream>

#define MAXN 32

using namespace std;

int main() {
    int n; cin >> n;
    int arr[3001] = {0}; int num;
    for(int i = 0; i < n; i++) {
        cin >> num;
        arr[num] = 1;
    }

    for(int i = 1; i <= 3000; i++) {
        if(arr[i] == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
#include <list>
#include <ctime>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <fstream>

#define MAXN 32

using namespace std;

int main() {
    int n; cin >> n;
    int arr[3001] = {0}; int num;
    for(int i = 0; i < n; i++) {
        cin >> num;
        arr[num] = 1;
    }

    for(int i = 1; i <= 3001; i++) {
        if(arr[i] == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
#include <list>
#include <ctime>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <fstream>

#define MAXN 32

using namespace std;

int main() {
    int n; cin >> n;
    int arr[3010] = {0}; int num;
    for(int i = 0; i < n; i++) {
        cin >> num;
        arr[num] = 1;
    }

    for(int i = 1; i <= 3010; i++) {
        if(arr[i] == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3100;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i==arr[j]){c++;}

		}
	if(c!=0){cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3000;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i!=arr[j]){c++;}

		}
	if(c==x){cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3001;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i!=arr[j]){c++;}

		}
	if(c==x){cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3100;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i!=arr[j]){c++;}

		}
	if(c==x){cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3100;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i==arr[j]){c++;}

		}
	if(c==0){cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here

	int x;
	cin>>x;
	int arr[x];
	for(int i=0;i<x;i++){
		cin>>arr[i];

	}
	for (int i=1;i<=3000;i++){
		int c=0;
		for(int j=0;j<x;j++){
			if (i!=arr[j]){c++;}

		}
	if(c==x){
cout<<i;
		break;
	}

	}

	return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3002] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3001){
    if(table[i] == 0) {
      cout << i << endl;
      break;
    }
  }

  return 1;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3001] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  rep(i,3001){
    if(table[i]!= 0) cout << i << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3002] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3001){
    if(table[i] == 0) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3002] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3002){
    if(table[i] == 0) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3001] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3001){
    if(table[i] == 0) {
      cout << i << endl;
      break;
    }
  }

  return 1;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3001] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  rep(i,3001){
    if(table[i] == 0) cout << i << endl;
    break;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3001] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3001){
    if(table[i] == 0) cout << i << endl;
    break;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>

#define rep(i,n) for((i) = 0;(i) < (n);(i)++)
#define REP(i,a,b) for((i) = (a);(i) < (b);(i)++)

using namespace std;

int table[3001] = {};

int main(){
  int n;cin >>n;
  int i;
  int buf;
  rep(i,n) {
    cin >> buf;
    table[buf] ++;
  }
  REP(i,1,3001){
    if(table[i] == 0) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
#define inf 0x3fffffff
using namespace std;
const int maxn=10010;
int a[maxn];
int main()
{
    int n,num;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        a[num]++;
    }
    num=1;
    while(1+1==2)
    {
        if(a[num])num++;
        else break;
    }
    printf("%d\n",num);
    return 0;
}
/*2017-07-29 19:19:26.263*/


#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100004
using namespace std;
typedef long long ll;
int a[3005];
int main()
{
    int i,j,n,m,x,y,b,c,flag=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(i=1;i<=3001;i++)
    {
        if(!a[i])
        {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}
/*2017-07-29 19:18:28.095*/


#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <algorithm>
#define MOD 10000007
using namespace std;

int main()
{
    bool vis[3005];
    int n, i, t;

    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &t);
        vis[t] = 1;
    }
    for (i = 1; i <= 3000; i++)
    {
        if (vis[i] == 0)
        {
            printf("%d\n", i);
            return 0;
        }
    }
}
/*2017-07-29 19:20:19.04*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[3005],b[3005];
int main()
{
    int flag=0,i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[a[i]]++;
        }
        for(i=1;i<=a[n-1]+1;i++)
        {
            if(b[i]==0)
            {
                printf("%d",i);
                break;
            }
        }
    return 0;
}
/*2017-07-29 19:37:59.299*/


#include<iostream>
using namespace std;

int num[3001];
int n;

int main()
{
	cin>>n;
	int a;
	for (int i=1;i<=n;i++)
	{
		cin>>a;
		num[a]++;
	}
	for (int i=1;i<4000;i++)
	{
		if (num[i]==0)
		{cout<<i<<endl;break;}
	}
}/*2017-11-30 11:06:57.068*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
   int a[100000];
   int n;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+n+1);
   for(int i=0;i<901000;i++)
   {
       if(a[i]!=i)
       {
         printf("%d",i);
         break;
       }
   }

}
/*2017-07-29 19:26:30.276*/


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;

    vector<int>v;

    while(t--)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());

    bool flag = true;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i+1)
        {
            flag = false;
            cout << i+1;
            break;
        }
    }
    if(flag)
        cout << v[v.size()-1]+1;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;

    vector<int>v;

    while(t--)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());

    if(v.size() == 1)
    {
        cout << v[0]+1;
        return 0;
    }
    bool flag = false;
    for(int i=1;i<v.size();i++)
    {
        if(v[i-1]+1 != (v[i]))
        {
            flag  =true;
            cout << v[i-1]+1;
            break;
        }
    }
    if(!flag)
        cout << v[v.size()-1]+1;
    //system("PAUSE");
    return 0;
}


/*
 * test.cpp
 *
 *  Created on: Jul 26, 2012
 *      Author: mfouad
 */

#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char **argv) {
    int arr[3000];

    for(int i=0;i<3000;i++)
        arr[i] = -1;

    int tt;
    cin >> tt;

    while(tt--)
    {
        int ind;
        cin >> ind;
        arr[ind-1] = 1;
    }

    for(int i=0;i<3000;i++)
    {
        if(arr[i] == -1)
        {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;

    vector<int>v;

    while(t--)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());

    if(v.size() == 1)
    {
        cout << v[0]+1;
        return 0;
    }
    for(int i=1;i<v.size();i++)
    {
        if(v[i-1]+1 != (v[i]))
        {
            cout << v[i-1]+1;
            break;
        }
    }
    //system("PAUSE");
    return 0;
}


/*
 * test.cpp
 *
 *  Created on: Jul 26, 2012
 *      Author: mfouad
 */

#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char **argv) {
    int arr[3001];

    for(int i=0;i<3001;i++)
        arr[i] = -1;

    int tt;
    cin >> tt;

    while(tt--)
    {
        int ind;
        cin >> ind;
        arr[ind-1] = 1;
    }

    for(int i=0;i<3001;i++)
    {
        if(arr[i] == -1)
        {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;

    vector<int>v;

    while(t--)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());

    for(int i=1;i<v.size();i++)
    {
        if(v[i-1]+1 != (v[i]))
        {
            cout << v[i-1]+1;
            break;
        }
    }
    //system("PAUSE");
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;

int gcd (int a, int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
bool isPrime(int n)
{
	if(n==1)
	{
		return false;
	}
	for (int i=2; i<=(int)sqrt(n); i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
 int main()
{
	int n;
	cin>>n;
	int ar[3001];
	for (int i=0; i<n; i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	int t =ar[0];
	int num =0;

	for (int i=0;i<n-1; i++ )
	{
		if(ar[i]+1!=ar[i+1])
		{
			cout << ar[i]+1;
			return 0;
		}
	}
	cout << ar[n-1]+1;
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;

int gcd (int a, int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
bool isPrime(int n)
{
	if(n==1)
	{
		return false;
	}
	for (int i=2; i<=(int)sqrt(n); i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
 int main()
{
	int n;
	cin>>n;
	int ar[3001];
	for (int i=0; i<n; i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	int num=0;
	for (int i=0; i<n-1; i++)
	{
		if(ar[i+1]!=ar[i]+1)
		{
			num = ar[i]+1;
			break;
		}
	}
	cout << num;
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;

int gcd (int a, int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
bool isPrime(int n)
{
	if(n==1)
	{
		return false;
	}
	for (int i=2; i<=(int)sqrt(n); i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
 int main()
{
	int n;
	cin>>n;
	int ar[3001];
	for (int i=0; i<n; i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	int num=0;
	if(n==1)
	{
		cout <<ar[0]+1;
		return 0;
	}
	for (int i=0; i<n-1; i++)
	{
		if(ar[i+1]!=ar[i]+1)
		{
			num = ar[i]+1;
			break;
		}
	}
	cout << num;
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
bool used[3005];
 int main()
{
	int n;
	cin>>n;
	int t;

	for (int i=0; i<n; i++)
	{
		cin>>t;
		used[t] = true;
	}
	for (int i=1; i<=3005; i++)
	{
		if(used[i]==0)
		{
			cout<< (i)<<endl;
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
bool used[300];
 int main()
{
	int n;
	cin>>n;
	int t;

	for (int i=0; i<n; i++)
	{
		cin>>t;
		used[t] = true;
	}
	for (int i=1; i<=3005; i++)
	{
		if(used[i]==0)
		{
			cout<< (i)<<endl;
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <fstream>
#pragma comment(linker, "/STACK:16777216")
using namespace std;

int gcd (int a, int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
bool isPrime(int n)
{
	if(n==1)
	{
		return false;
	}
	for (int i=2; i<=(int)sqrt(n); i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
 int main()
{
	int n;
	cin>>n;
	int ar[3001];
	for (int i=0; i<n; i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	int t =ar[0];
	int num =0;
	if(n==1)
	{
		cout << ar[0]+1;
	}
	for (int i=0;i<n-1; i++ )
	{
		if(ar[i]+1!=ar[i+1])
		{
			cout << ar[i]+1;
			return 0;
		}
	}
	cout << ar[n-1]+1;
	return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=1000010,k;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
                        {scanf("%d",&k);
                         a[k]=1;
                         }

for(int i=1;i<=4000;i++)
{
        if(a[i]!=1) {printf("%d",i); break;}
}

    //getch();
    return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=1000010,k;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
                        {scanf("%d",&k);
                         a[k]=1;
                         }

for(int i=1;i<3000;i++)
{
        if(a[i]!=1) {printf("%d",i); break;}
}

    //getch();
    return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=10000;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
            {
                        scanf("%d",&a[i]);
                        if(a[i]<min) min=a[i];
            }

    for(int i=0;i<n;i++)
    {
            if((min+x)==a[i])
            x++;
    }

printf("%d",min+x);

    //getch();
    return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=10000;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
            {
                        scanf("%d",&a[i]);
                        if(a[i]<min) min=a[i];
            }

            if(min>1) {printf("1"); return 0;}

else{
        for(int i=0;i<n;i++)
          {
              if((min+x)==a[i])
              x++;
          }

         printf("%d",min+x);

   }

    //getch();
    return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=1000010;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
            {
                        scanf("%d",&a[i]);
                        if(a[i]<min) min=a[i];
            }

            if(min>1) {printf("1"); return 0;}

else{
        for(int i=0;i<=3000;i++)
          {
              if((min+x)==a[i])
              x++;
          }

         printf("%d",min+x);

   }

    //getch();
    return 0;
}


#include <iostream>
#include <algorithm>
//#include <conio.h>

using namespace std;

int main()
{
    int n;
    int a[3300],t=1;
    cin>>n;
    for(int i=0;i<n;++i)
       cin>>a[i];

    sort(a,a+n);
    for(int i=0;i<n;++i)
    {
            if(a[i]!=t) {cout<<t; goto end;}
            else
            {
                while(a[i]==t)
                {
                                ++i;
                }
            }
            --i;
            ++t;
    }
    cout<<a[n-1]+1;
    end:
   // getch();
    return 0;
}


#include <iostream>
#include <algorithm>
//#include <conio.h>

using namespace std;

int main()
{
    int n;
    int a[3300];
    cin>>n;
    for(int i=0;i<n;++i)
       cin>>a[i];

    sort(a,a+n);
    for(int i=0;i<n;++i)
    {
            if(a[i]+1!=a[i+1]) {cout<<a[i]+1; goto end;}
    }
    cout<<a[n-1]+1;
    end:
 //   getch();
    return 0;
}


#include <cstdio>
//#include <conio.h>

int main()
{
    int x=1,n,a[3000],min=1000010;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
            {
                        scanf("%d",&a[i]);
                        if(a[i]<min) min=a[i];
            }

            if(min>1) {printf("1"); return 0;}

else{
        for(int i=0;;i++)
          {
              if((min+x)==a[i])
              x++;
          }

         printf("%d",min+x);

   }

    //getch();
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  bool a[3002];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==false){
      printf("%d\n",n);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3002];
int main(){
  int n,v;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==0){
      printf("%d\n",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  bool a[3001];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
 // for(int i=1;i<=3000;i++)
   // if(a[i]==false){
      printf("%d\n",n);//break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  bool a[3002];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==false){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  bool a[3001];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3000;i++)
    if(a[i]==false){
      printf("%d\n",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  bool a[3002];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==false){
      printf("%d\n",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,v;
  int a[3002];
  memset(a,0,sizeof(a));
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==0){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3002];
int main(){
  int n,v;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3000;i++)
    if(a[i]==0){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3002];
int main(){
  int n,v;
  memset(a,0,sizeof(a));
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==0){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,v;
  int a[3002];
  memset(a,0,sizeof(a));
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==0){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3002];
int main(){
  int n,v;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v);
    a[v]=1;
  }
  for(int i=1;i<=3001;i++)
    if(a[i]==0){
      printf("%d",i);break;}
//  system("PAUSE");
  return 0;
  }


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,x;
bool a[3100];
inline long long read()
{
  long long cnt=0,f=1;char ch=getchar();
  while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
  while (ch>='0'&&ch<='9'){cnt=cnt*10+ch-48;ch=getchar();}
  return cnt*f;
}
int main()
{
  n=read();
  for (int i=1;i<=n;i++)
   {
   	x=read();
   	a[x]=true;
   }
  for (int i=1;i<=n;i++)
   if (!a[i])
    {
      printf("%d\n",i);
      return 0;
    }
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,x;
bool a[3100];
inline long long read()
{
  long long cnt=0,f=1;char ch=getchar();
  while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
  while (ch>='0'&&ch<='9'){cnt=cnt*10+ch-48;ch=getchar();}
  return cnt*f;
}
int main()
{
  while (scanf("%d",&n)&&n)
  {
  memset(a,false,sizeof(a));
  for (int i=1;i<=n;i++)
   {
   	x=read();
   	a[x]=true;
   }
  for (int i=1;i<=4000;i++)
   if (!a[i])
    {
      printf("%d\n",i);
      break;
    }
  }
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,x;
bool a[3100];
inline long long read()
{
  long long cnt=0,f=1;char ch=getchar();
  while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
  while (ch>='0'&&ch<='9'){cnt=cnt*10+ch-48;ch=getchar();}
  return cnt*f;
}
int main()
{
  n=read();
  for (int i=1;i<=n;i++)
   {
   	x=read();
   	a[x]=true;
   }
  for (int i=1;i<=n;i++)
   if (!a[i])
    {
      printf("%d",i);
      return 0;
    }
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int hs[40000];
int main()
{
      int n ;
    scanf("%d",&n);
    memset(hs,0,sizeof(hs));
    for(int i = 1;i <= n;i ++)
    {
      int temp ;
      scanf("%d",&temp);
      hs[temp] = 1;
    }
    for(int i = 1;i <= 4000;i ++)
        if(hs[i] == 0)
        {
         printf("%d\n",i);
         break;
        }
        return 0;
}


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def get_ans(arr,s,e,k):
    t=list(arr[s:e+1])
    t.sort(reverse=True)
    dont=0
    for i in range(len(t)):
        cnt,br=t[i][0],t[i][1]
        if br<=k:
            k-=br
            dont+=cnt
    return dont

def solve():
    n,q=IP()
    li=L()
    mx=-1
    ans=0
    pos=-1
    note=(n-1)
    for i in range(n):
        if mx>li[i]:
            pos=max(pos,mx-li[i])
            note=i
        mx=max(mx,li[i])
    if note!=(n-1):
        pos+=li[-1]
    ans=max(max(li),pos)
    P(ans)
    return

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def solve():
    n,q=IP()
    a=L()
    if n%2:
        c=(n+1)//2
    else:
        c=n//2
    mx=-1
    ans=0
    for i in range(n):
        if a[i]>c:
            mx=max(mx,a[i])
        elif a[i]<c:
            if (mx!=-1):
                ans+=(mx-a[i])
            mx=-1
    if mx!=-1:
        ans+=mx
    P(ans)

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def solve():
    n,q=IP()
    a=L()
    d1=[0 for i in range(n+1)]
    d2=[0 for i in range(n+1)]
    for i in range(n):
        d1[i+1]=max(d2[i]+a[i],d1[i+1],a[i],d1[i])
        d2[i+1]=max(d1[i]-a[i],d2[i+1],d2[i])
    print(max(d1[n],d2[n]))

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def get_ans(arr,s,e,k):
    t=list(arr[s:e+1])
    t.sort(reverse=True)
    dont=0
    for i in range(len(t)):
        cnt,br=t[i][0],t[i][1]
        if br<=k:
            k-=br
            dont+=cnt
    return dont

def solve():
    n,q=IP()
    li=L()
    mx=-1
    ans=0
    last=-1
    nt=max(li)+5
    mn=max(li)+5
    lst=False
    for i in range(n):
        if mx==-1:
            mx=li[i]
        else:
            if mx>li[i]:
                mn=min(mn,li[i])
            else:
                if mn!=nt and mx!=-1:
                    if i==(n-1):
                        ans+=mx
                        lst=True
                    else:
                        ans+=(mx-mn)
                    mn=nt
                mx=li[i]
    if not(lst):
        ans+=mx
    P(ans)
    return

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def solve():
    n,q=IP()
    li=L()
    d={}
    nt=1+n
    ans=0
    for i in range(n):
        d[li[i]]=i
    l,r=-1,-1
    if n%2!=0:
        end=(n//2)+1
    else:
        end=(n//2)
    for i in range(n,end,-1):
        #print(l,r)
        fnd=d[nt-i]
        pos=d[i]
        if fnd>pos:
            if l==-1 and r==-1:
                l=pos
                r=fnd
                ans+=(i-(nt-i))
                #print(i,ans)
            else:
                if (fnd<l and pos<l) or (fnd>r and pos>r):
                    l=min(pos,l)
                    r=max(fnd,pos)

                    ans+=(i-(nt-i))
                    #print(i,ans)
    mx=0
    for i in range(r+1,n):
        #print(i,li[i])
        mx=max(mx,li[i])
    P(ans+mx)
    return

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*(2*(10**5)+5)
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range((2*(10**5)+5)):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
    spf[1]=1
    for i in range(2,mx+1):
        if spf[i]==mx:
            spf[i]=i
            for j in range(i*i,mx+1,i):
                if i<spf[j]:
                    spf[j]=i
    return
def readTree(n,e): # to read tree
    adj=[set() for i in range(n+1)]
    for i in range(e):
        u1,u2=IP()
        adj[u1].add(u2)
    return adj
#####################################################################################
mod=10**9+7
def solve():
    n,q=IP()
    a=L()
    d1=[0 for i in range(n+1)]
    d2=[0 for i in range(n+1)]
    for i in range(n):
        d1[i+1]=max(d2[i]+a[i],d1[i])
        d2[i+1]=max(d1[i]-a[i],d2[i])
    print(max(d1[n],d2[n]))

t=II()
for i in range(t):
    solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #


for _ in range(int(input())):
    n,q = map(int,input().split(' '))
    arr = [int(num) for num in input().split(' ')]
    dp_odd = [0 for x in range(n+1)]
    dp_even = [0 for x in range(n+1)]
    inf = 10**18
    dp_odd[0] = 0
    dp_even[0] = 0
    for i in range(1,n+1):
        dp_odd[i] = max(dp_odd[i-1],dp_even[i-1] + arr[i-1])
        dp_even[i] = max(dp_even[i-1],dp_odd[i-1] - arr[i-1])
        ans = max(dp_even[i],dp_odd[i])

    print(ans)


for _ in range(int(input())):
    n,q = map(int,input().split(' '))
    arr = [int(num) for num in input().split(' ')]
    dp_odd = [0 for x in range(n+1)]
    dp_even = [0 for x in range(n+1)]
    ing = 10**18
    dp_odd[0] = -ing
    dp_even[0] = 0
    for i in range(1,n+1):
        dp_odd[i] = max(dp_odd[i-1],dp_even[i-1] + arr[i-1])
        dp_even[i] = max(dp_even[i-1],dp_odd[i-1] - arr[i-1])
        ans = max(dp_even[i],dp_odd[i])

    print(ans)


for _ in range(int(input())):
    n,q = map(int,input().split(' '))
    arr = [int(num) for num in input().split(' ')]
    dp_odd = [0 for x in range(n+1)]
    dp_even = [0 for x in range(n+1)]
    inf = 10**18
    dp_odd[0] = -inf
    dp_even[0] = 0
    for i in range(1,n+1):
        dp_odd[i] = max(dp_odd[i-1],dp_even[i-1] + arr[i-1])
        dp_even[i] = max(dp_even[i-1],dp_odd[i-1] - arr[i-1])
        ans = max(dp_even[i],dp_odd[i])

    print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict,Counter
from math import factorial as fac
MAX = 10**10

def main():
    t = int(input())
    for _ in range(t):
        n,q= map(int,input().split())
        arr = list(map(int,input().split()))
        ans = 0
        maximum = max(arr)

        for i in range(n):
            num = arr[i]
            minn = MAX
            minn_idx = -1
            if num!=-1:
                for j in range(i+1,n):
                    if arr[j]!=-1 and arr[j]<num and arr[j]<minn:
                        minn = arr[j]
                        minn_idx = j

                if minn_idx>0 and (minn != MAX):
                    ans += arr[i] - arr[minn_idx]
                    arr[minn_idx] = -1
                    arr[i] = -1
                    #print(arr)

        rem = -MAX
        for i in range(n-1,-1,-1):
            if arr[i] == -1:
                break
            rem = max(rem,arr[i])

        #print(f're = {rem}')
        #print(arr)

        if rem!=(-MAX):
            ans = ans + rem

        if ans>maximum:
            print(ans)
        else:
            print(maximum)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


t = int(input())
for _ in range(t):
    n,q= map(int,input().split())
    arr = list(map(int,input().split()))
    ans = 0
    for i in range(n-1):
        if arr[i]>arr[i+1]:
            ans += arr[i]-arr[i+1]

    ans += arr[n-1]
    print(ans)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
import math
from collections import Counter,defaultdict,deque
def int1():
    return int(input())
def map1():
    return map(int,input().split())
def list1():
    return list(map(int,input().split()))
mod=pow(10,9)+7
def solve():
    n,q=map1()
    l1=list1()
    sum1,i=0,0
    flag=0
    max1=0
    while(1):
        if(i==(n-1)):
            max1=max(max1,l1[i])
            #print(sum1,max1)
            print(max1+sum1)
            return
        if(l1[i]<l1[i+1]):
            i=i+1
            c1=l1[i-1]
            if(flag==1):
                sum1+=(c-c1)
                max1=0
            flag=0
            max1=max(max1,l1[i])
            #print(sum1,max1,i)
        else:
            if(flag==0):
                c=l1[i]
            flag=1
            i=i+1
            #print(sum1,max1)
for _ in range(int(input())):
    solve()


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
import math
from collections import Counter,defaultdict,deque
def int1():
    return int(input())
def map1():
    return map(int,input().split())
def list1():
    return list(map(int,input().split()))
mod=pow(10,9)+7
def solve():
    n,q=map1()
    l1=list1()
    sum1,i=0,0
    flag=0
    max1=0
    while(1):
        if(i==(n-1)):
            max1=max(max1,l1[i])
            #print(sum1,max1)
            print(max(n,max1+sum1))
            return
        if(l1[i]<l1[i+1]):
            i=i+1
            c1=l1[i-1]
            if(flag==1):
                sum1+=(c-c1)
                max1=0
            flag=0
            max1=max(max1,l1[i])
            #print(sum1,max1,i)
        else:
            if(flag==0):
                c=l1[i]
            flag=1
            i=i+1
            #print(sum1,max1)
for _ in range(int(input())):
    solve()


from sys import stdin
from math import log2

def readline():
    return stdin.readline()

def solve(n, a):
    a = [-1, *a, 0]
    sm = 0
    mine = 0
    for i in range(1, n + 1):
        if a[i - 1] < a[i] > a[i + 1]:
            sm += a[i]
            mine = 0
        elif a[i - 1] > a[i] < a[i + 1]:
            sm -= a[i]
            mine = a[i]
    sm += mine
    return sm

tests = int(readline())
for t in range(0, tests):
    n, q = map(int, readline().split())
    a = list(map(int, readline().rstrip("\n").split(' ')))

    print(solve(n, a))


from sys import stdin
from math import log2

def readline():
    return stdin.readline()

def solve(n, a):
    maxe, maxo = 0, 0

    for i in a:
        maxe, maxo = max(maxe, maxo + i), max(maxo, maxe - i)

    return max(maxe, maxo)

tests = int(readline())
for t in range(0, tests):
    n, _ = map(int, readline().split())
    a = list(map(int, readline().rstrip("\n").split(' ')))

    print(solve(n, a))


t=int(input())
for _ in range(t):
    n,q=list(map(int,input().split()))
    a=list(map(int,input().split()))
    ans=max(a)
    x=0
    z=0
    f=0
    for i in range(n-1):
        if a[i]>=a[i+1]:
            x=max(x,a[i])
            f=1
        else:
            if f:
                z=z+x-a[i]
                f=0
                x=0
            else:
                x=max(x,a[i])
    if f==0:
        x=max(x,a[-1])
    z=z+x
    ans=max(ans,z)
    print(ans)


t=int(input())
for _ in range(t):
    n,q=list(map(int,input().split()))
    a=list(map(int,input().split()))
    ans=max(a)
    x=0
    z=0
    f=0
    for i in range(n-1):
        if a[i]>=a[i+1]:
            x=max(x,a[i])
            f=1
        else:
            if f:
                z=z+x-a[i]
                f=0
                x=0
            else:
                x=max(x,a[i])
    z=z+x
    ans=max(ans,z)
    print(ans)


t=int(input())
for _ in range(t):
    n,q=list(map(int,input().split()))
    a=list(map(int,input().split()))
    ans=max(a)
    x=0
    z=0
    for i in range(n-1):
        if a[i]>=a[i+1]:
            z=z+a[i]-a[i+1]
            x=1
        else:
            x=0
    if x==0:
        z=z+a[-1]
    ans=max(ans,z)
    print(ans)


def maximal_power(l):
    res = 0
    big = 0
    small = 1000000
    for i in range(0, len(l)):
        if(l[i] >= big):
            if(small < big):
                res += big - small
                big = 0
                small = 1000000
            else:
                big = l[i]
        if(l[i] < big):
            if(l[i] < small):
                small = l[i]
            else:
                res += big - small
                big = l[i]
                small = 1000000
    res += big
    return res

t = int(input())
for i in range(t):
    n, q = map(int, input().split())
    l = list(map(int, input().split()))
    print(maximal_power(l))


def maximal_power(l):
    res = 0
    big = 0
    small = 1000000
    for i in range(0, len(l)):
        if(l[i] >= big):
            if(small < big):
                res += big - small
                big = 0
                small = 1000000
            else:
                big = l[i]
        if(l[i] < big and l[i] < small):
            small = l[i]
    res += big
    return res

t = int(input())
for i in range(t):
    n, q = map(int, input().split())
    l = list(map(int, input().split()))
    print(maximal_power(l))


def maximal_power(l):
    res = 0
    last = 0
    for i in l:
        if(i > last):
            res += i - last
        last = i
    return res

t = int(input())
for i in range(t):
    n, q = map(int, input().split())
    l = list(map(int, input().split()))
    print(maximal_power(l))


import sys
from bisect import bisect
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict

def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())

def solution():
     for _ in range(Int()):
          n,q=Mint()
          a=list(Mint())
          ok=0
          tot=0
          for i in range(1,n):
               if(i==n-1):
                    if(ok==0):
                         tot+=a[i]
                    break
               if(ok==0):
                    if(a[i-1]<a[i]):
                         if(a[i]>a[i+1]):
                              ok=1
                              tot+=(a[i])

               else:
                    if(a[i-1]>a[i]):
                         if(a[i]<a[i+1]):
                              ok=0
                              tot-=(a[i])
          print(tot)

#Call the solve function
if __name__ == "__main__":
     solution()


import sys
from bisect import bisect
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict

def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())

def solution():
     for _ in range(Int()):
          n,q=Mint()
          a=list(Mint())
          a.append(0)
          ok=0
          tot=0
          for i in range(1,n):
               if(ok==0):
                    if(a[i-1]<a[i]):
                         if(a[i]>a[i+1]):
                              ok=1
                              tot+=(a[i])

               else:
                    if(a[i-1]>a[i]):
                         if(a[i]<a[i+1]):
                              ok=0
                              tot-=(a[i])
          print(tot)

#Call the solve function
if __name__ == "__main__":
     solution()


import sys
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict

def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())

def solution():
     for _ in range(Int()):
          n,q=Mint()
          a=list(Mint())
          a.append(0)
          ok=0
          ans=[]
          for i in range(1,n):
               if(ok==0):
                    if(a[i-1]<a[i]):
                         if(a[i]>a[i+1]):
                              ok=1
                              ans.append(a[i])

               else:
                    if(a[i-1]>a[i]):
                         if(a[i]<a[i+1]):
                              ok=0
                              ans.append(a[i])
          ok=0
          tot=0
          for i in range(len(ans)):
               if(ok==0):
                    tot+=ans[i]
                    ok=1
               else:
                    tot-=ans[i]
                    ok=0
          print(tot)

#Call the solve function
if __name__ == "__main__":
     solution()


import sys
from bisect import bisect
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict

def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())

def solution():
     for _ in range(Int()):
          n,q=Mint()
          a=list(Mint())
          ok=0
          tot=0
          for i in range(n):
               if(i==n-1):
                    if(ok==0):
                         tot+=a[i]
                    break
               if(ok==0):
                    if(a[i]>a[i+1]):
                         ok=1
                         tot+=(a[i])

               else:
                    if(a[i]<a[i+1]):
                         ok=0
                         tot-=(a[i])
          print(tot)

#Call the solve function
if __name__ == "__main__":
     solution()


import sys
from bisect import bisect
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict

def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())

def solution():
     for _ in range(Int()):
          n,q=Mint()
          a=list(Mint())
          ok=0
          ans=[]
          for i in range(1,n-1):
               if(ok==0):
                    if(a[i-1]<a[i]):
                         if(a[i]>a[i+1]):
                              ok=1
                              ans.append(a[i])

               else:
                    if(a[i-1]>a[i]):
                         if(a[i]<a[i+1]):
                              ok=0
                              ans.append(a[i])
          if(ok==0):
               ans.append(a[-1])
          ans=list(set(ans))
          ok=0
          tot=0
          for i in range(len(ans)):
               if(ok==0):
                    tot+=ans[i]
                    ok=1
               else:
                    tot-=ans[i]
                    ok=0
          print(tot)

#Call the solve function
if __name__ == "__main__":
     solution()


from collections import defaultdict
t = int(input())
for _ in range(t):
    n,q = list(map(int,input().split()))
    l = list(map(int,input().split()))
    if n==1:
        print(l[0])
        continue
    ans = 0
    f = 0
    if l[1]>l[0]:
        f = 1
    # if f==1 increasing
    prev = l[0]
    nextt = 0
    for i in range(1,n):
        if l[i]>l[i-1]:
            if f==0:
                ans+=(prev-l[i-1])
                f = 1
        else:
            if f==1:
                prev = l[i-1]
                f = 0
    if f==0:
        ans+=max((prev-l[i]),l[-1],prev)
    else:
        ans+=l[-1]
    print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
    n,q = list(map(int,input().split()))
    l = list(map(int,input().split()))
    if n==1:
        print(l[0])
        continue
    ans = 0
    f = 0
    if l[1]>l[0]:
        f = 1
    # if f==1 increasing
    prev = l[0]
    nextt = 0
    for i in range(1,n):
        if l[i]>l[i-1]:
            if f==0:
                ans+=(prev-l[i-1])
                f = 1
        else:
            if f==1:
                prev = l[i-1]
                f = 0
    if f==0:
        ans+=(prev-l[i])
    else:
        ans+=l[-1]
    print(ans)


import math
for _ in range(int(input())):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))

    ma = -1
    mi = 1e9
    c = 0
    flag = 0
    ans  = []
    for i in range(n):
        if flag == 0:
            if ma < a[i]:
                ma = a[i]

            elif ma > a[i]:
                c+= ma
                ans.append(ma)
                flag = 1
                mi = a[i]
                ma = -1

        else:
            if mi > a[i]:
                mi = a[i]

            elif mi < a[i]:
                c-= mi
                ans.append(mi)
                flag = 0
                ma = a[i]
                mi = 1e9

    if flag == 0:
        c+= a[n-1]

    print(c)


import math
for _ in range(int(input())):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))

    ma = -1
    mi = 1e9
    c = 0
    flag = 0
    ans  = []
    for i in range(n):
        if flag == 0:
            if ma < a[i]:
                ma = a[i]

                if i == n-1:
                    c += ma
                    ans.append(ma)
            elif ma > a[i]:
                c+= ma
                ans.append(ma)
                flag = 1
                mi = a[i]
                ma = -1

        else:
            if mi > a[i]:
                mi = a[i]

            elif mi < a[i]:
                c-= mi
                ans.append(mi)
                flag = 0
                ma = a[i]
                mi = 1e9

    print(c)
    #print(mi,ma)
    #print(ans)


import math
for _ in range(int(input())):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))

    ma = -1
    mi = 1e9
    c = 0
    flag = 0
    ans  = []
    for i in range(1,n):
        if flag == 0:
            if a[i]>a[i-1]:
                cur = a[i]

            else:
                c+= a[i-1]
                #ans.append(ma)
                flag = 1
                cur = a[i]

        else:
            if a[i-1] > a[i]:
                cur = a[i]

            else:
                c -= a[i-1]
                #ans.append(mi)
                flag = 0
                cur = a[i]

    if flag == 0:
        c+= a[n-1]

    print(c)
    #print(mi,ma)
    #print(ans)


import math
for _ in range(int(input())):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))

    ma = -1
    mi = 100000
    c = 0
    flag = 0
    ans  = []
    for i in range(n):
        if flag == 0:
            if ma < a[i]:
                ma = a[i]

                if i == n-1:
                    c += ma
                    ans.append(ma)
            elif ma > a[i]:
                c+= ma
                ans.append(ma)
                flag = 1
                mi = a[i]

        else:
            if mi > a[i]:
                mi = a[i]

            elif mi < a[i]:
                c-= mi
                ans.append(mi)
                flag = 0
                ma = a[i]

    print(c)
    #print(mi,ma)
    #print(ans)


import collections
for t in range(int(input())):
    n,q=map(int,input().split())
    num=list(map(int,input().split()))
    out=0
    flag=1
    for i in range(n-1):
        if flag:
            if num[i]>num[i+1]:
                out+=num[i]
                flag=0
        else:
            if num[i]<num[i+1]:
                out-=num[i]
                flag=1
    if flag:
        out+=num[-1]
    print(out)


for _ in range(int(input())):
	n,q = map(int,input().split())
	l = list(map(int,input().split()))
	i, pos, neg = 0,[],[]
	#reg = 1 if l[1] >= l[0] else 0
	while i < n:
		j = i

		while j+1 < n and l[j+1] >= l[j]:
			j += 1
		if j != n:
			pos.append(l[j])
			i = j+1
		else:
			break
		j = i
		while j+1 < n and l[j+1] <= l[j]:
			j += 1
		if j != n:
			neg.append(l[j])
			i = j+1
		else:
			break
	#print(pos,neg,sep='\n')
	if len(neg) == len(pos):
		print(sum(pos) - (sum(neg) - neg[-1]))
	else:
		print(sum(pos) - sum(neg))


for _ in range(int(input())):
	n,q = map(int,input().split())
	l = list(map(int,input().split()))
	i, reg, pos, neg = 1,1,[],[]
	while i < n:
		j = i
		while j+1 < n and l[j+1] >= l[j]:
			j += 1
		if j != n:
			pos.append(l[j])
			i = j+1
		else:
			break
		j = i
		while j+1 < n and l[j+1] <= l[j]:
			j += 1
		if j != n:
			neg.append(l[j])
			i = j+1
		else:
			break
	#print(pos,neg,sep='\n')
	if len(neg) == 1 and len(pos) == 1:
		print(sum(pos))
	else:
		print(sum(pos) - sum(neg))


import math
t = int(input())
for _ in range(t):
	n,q = list(map(int,input().split(" ")))
	a = list(map(int,input().split(" ")))

	dp1 = [-1e6]
	dp2 = [0]

	for i in a:
		dp1.append(max(dp1[-1],dp2[-1]+i))
		dp2.append(max(dp2[-1],dp1[-1]-i))
	print(max(dp1[-1],dp2[-1]))


import math
t = int(input())
for _ in range(t):
	n,q = list(map(int,input().split(" ")))
	a = list(map(int,input().split(" ")))
	s = set()
	ans = 0
	if a[0] > a[1]:
		ans += a[0]
	for i in range(1,n-1):
		if a[i] > a[i-1] and a[i] > a[i+1]:
			ans += a[i]
		elif a[i] < a[i-1] and a[i] < a[i+1]:
			ans -= a[i]
	if a[-1] > a[-2]:
		ans += a[-1]
	print(ans)


import math
t = int(input())
for _ in range(t):
	n,q = list(map(int,input().split(" ")))
	a = list(map(int,input().split(" ")))
	#s = set()
	ans = 0
	if n==1:
		print(a[0])
	elif n==2:
		print(max(a[0],a[1]))
	else:
		if a[0] > a[1]:
			ans += a[0]
		for i in range(1,n-1):
			if a[i] > a[i-1] and a[i] > a[i+1]:
				ans += a[i]
			elif a[i] < a[i-1] and a[i] < a[i+1]:
				ans -= a[i]
		if a[-1] > a[-2]:
			ans += a[-1]
		print(ans)


import sys
input = sys.stdin.readline

import copy
t = int(input())
for i in range(t):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    flg = 0
    ans = 0
    if n != 1:

        if a[0] > a[1]:
            flg += 1
            ans += a[0]
        for j in range(n-2):
            if a[j] < a[j+1] > a[j+2]:
                flg += 1
                ans+= a[j+1]
            if a[j] > a[j+1] < a[j+2]:
                flg += 1
                ans -= a[j+1]
    if flg %2 == 0:
        ans += a[n-1]
    print(ans)


import sys
input = sys.stdin.readline

import copy
t = int(input())
for i in range(t):
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    flg = 0
    ans = 0
    if a[0] > a[1]:
        flg += 1
        ans += a[0]
    for j in range(n-2):
        if a[j] < a[j+1] > a[j+2]:
            flg += 1
            ans+= a[j+1]
        if a[j] > a[j+1] < a[j+2]:
            flg += 1
            ans -= a[j+1]
    if flg %2 == 0:
        ans += a[n-1]
    print(ans)


from sys import stdin
###############################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
###############################################################

def localMaxima(arr, d):
    if d == 0:
        if arr[d]>arr[d+1]:
            return True
    elif d == len(arr)-1:
        if arr[d]>arr[d-1]:
            return True
    elif arr[d+1] < arr[d] >arr[d-1]:
        return True
    return False

def localMinima(arr, d):
    if d == 0:
        if arr[d]>arr[d+1]:
            return True
    elif d == len(arr)-1:
        if arr[d]>arr[d-1]:
            return True
    elif arr[d+1] < arr[d] >arr[d-1]:
        return True
    return False

t = iinput()
while t:
    t -= 1
    n, q = minput()
    a = linput()
    if n == 1:
        print(a[0])
    else:
        x = 1
        strength = 0
        prev = 0
        if a[0] > a[1]:
            x = 0
            strength += a[0]
            prev = a[0]
        i = 1
        while i<n:
            if x:
                while i<n:
                    if a[i] > a[i-1]:
                        i += 1
                    else: break
                strength += a[i-1]
                prev = a[i-1]
                x ^= 1
            else:
                while i<n:
                    if a[i] < a[i-1]:
                        i += 1
                    else: break
                strength -= a[i-1]
                prev = a[-1]
                x ^= 1
        if x:
            strength += prev
        print(strength)


from sys import stdin
###############################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
###############################################################

t = iinput()
while t:
    t -= 1
    n, q = minput()
    arr = linput()
    mn, mx = [], []
    x = 0
    i = -1
    while i<n:
        if x:
            for j in range(i+1, n-1):
                if arr[j]>arr[j+1]:
                    mx.append(j)
                    x^=1
                    break
            else:
                mx.append(n-1)
                x^=1

            i = j
        else:
            for j in range(i+1, n-1):
                if arr[j]<arr[j+1]:
                    mn.append(j)
                    x^=1
                    i = j
                    break
            else:
                break

    profit = 0
    for i in range(min(len(mn), len(mx))):
        profit += arr[mx[i]]-arr[mn[i]]
    print(profit + arr[mn[0]])


import sys
input=sys.stdin.readline

T=int(input())
for _ in range(T):
    N,q=map(int,input().split())
    A=list(map(int,input().split()))

    B=[[A[N-1],0]]
    j=0
    for i in range(N-2,-1,-1):
        val1=max(A[i],A[i]+B[j][1],B[j][0])
        val2=max(-A[i],-A[i]+B[j][0],B[j][1])
        B.append([val1,val2])
        j=j+1

    #print(B)
    print(max(B[N-1]))


import sys
input=sys.stdin.readline

T=int(input())
for _ in range(T):
    N,q=map(int,input().split())
    A=list(map(int,input().split()))

    B=[[A[N-1],0]]
    j=0
    for i in range(N-2,-1,-1):
        val1=max(A[i],A[i]+B[j][1],B[j][0])
        val2=max(-A[i],-A[i]+B[j][0],B[j][1])
        B.append([val1,val2])
        j=j+1

    #print(B)
    print(max(val1,val2))


def getint():
    return int(input())

def getints():
    return map(int, input().split())

def getlistints():
    return list(map(int, input().split()))
'''
def solution(n, nums):
    dp = [[0] * 2 for _ in range(n)]
    # dp[i][j] max sequence until i; j = 0: end in pos, 1: end in neg
    dp[0][0] = nums[0]
    for i in range(1, n):
        dp[i][0] = max(dp[i-1][0], dp[i-1][1] + nums[i])
        dp[i][1] = max(dp[i-1][1], dp[i-1][0] - nums[i])
    #print(dp)
    return max(dp[-1])
'''
def solution1(n, nums):
    nums = [-1] + nums + [-1]
    res = 0
    for i in range(1, n+1):
        if nums[i] < nums[i-1] and nums[i] < nums[i+1]:
            res -= nums[i]
        if nums[i] > nums[i-1] and nums[i] > nums[i+1]:
            res += nums[i]
    return res

if __name__ == "__main__":
    for _ in range(getint()):
        n, q = getints()
        nums = getlistints()
        #print(solution(n, nums))
        print(solution1(n, nums))


def getint():
    return int(input())

def getints():
    return map(int, input().split())

def getlistints():
    return list(map(int, input().split()))

def solution(n, nums):
    dp = [[0] * 2 for _ in range(n)]
    # dp[i][j] max sequence until i; j = 0: end in pos, 1: end in neg
    dp[0][0] = nums[0]
    for i in range(1, n):
        dp[i][0] = max(dp[i-1][0], dp[i-1][1] + nums[i])
        dp[i][1] = max(dp[i-1][1], dp[i-1][0] - nums[i])
    #print(dp)
    return max(dp[-1])

if __name__ == "__main__":
    for _ in range(getint()):
        n, q = getints()
        nums = getlistints()
        print(solution(n, nums))


n = int(input())
for j in range(n):
    ans = 0
    peak = []
    trough = []
    length, q = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]

    if (length == 1):
        print(arr[0])
    else:
        if(arr[0] > arr[1]):
            peak.append[0]
        for i in range(1, length-1):
            if (arr[i+1] < arr[i]) and arr[i] > arr[i-1]:
                peak.append(i)
            elif (arr[i+1] > arr[i]) and (arr[i-1] > arr[i]) and (len(peak) > 0):
                trough.append(i)
        if (arr[length-1] > arr[length - 2]):
            peak.append(len(arr) - 1)
        for p in peak:
            ans = ans + arr[p]
        for t in trough:
            ans = ans - arr[t]

        print(ans)


n = int(input())
for j in range(n):
    ans = 0
    peak = []
    trough = []
    length, q = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]
    if(arr[0] > arr[1]):
        peak.append[0]
    for i in range(1, length-1):
        if (arr[i+1] < arr[i]) and arr[i] > arr[i-1]:
            peak.append(i)
        elif (arr[i+1] > arr[i]) and (arr[i-1] > arr[i]) and (len(peak) > 0):
            trough.append(i)
    if (arr[len(arr)-1] > arr[len(arr) - 2]):
        peak.append(len(arr) - 1)
    for p in peak:
        ans = ans + arr[p]
    for t in trough:
        ans = ans - arr[t]

    print(ans)


n = int(input())
for j in range(n):
    ans = 0
    peak = []
    trough = []
    length, q = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]

    if (length == 1):
        print(arr[0])
    else:
        if(arr[0] > arr[1]):
            peak.append(0)
        for i in range(1, length-1):
            if (arr[i+1] < arr[i]) and arr[i] > arr[i-1]:
                peak.append(i)
            elif (arr[i+1] > arr[i]) and (arr[i-1] > arr[i]) and (len(peak) > 0):
                trough.append(i)
        if (arr[length-1] > arr[length - 2]):
            peak.append(len(arr) - 1)
        for p in peak:
            ans = ans + arr[p]
        for t in trough:
            ans = ans - arr[t]

        print(ans)


# https://codeforces.com/contest/1420/problem/C1
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
t = int(input())
for _ in range(t):
    n, q = map(int, input().split())
    arr = list(map(int, input().split()))
    peaks = []
    for x in range(n):
        left = (x-1 < 0) or arr[x-1] < arr[x]
        right = (x+1 >= n) or arr[x+1] < arr[x]
        if left and right:
            peaks.append(x)
    # print(peaks)
    i = 0
    j = 1
    ans = sum([arr[x] for x in peaks])
    while j < len(peaks):
        ans -= min(arr[peaks[i]+1:arr[peaks[j]]])
        j += 1
    print(ans)


# https://codeforces.com/contest/1420/problem/C1
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
t = int(input())
for _ in range(t):
    n, q = map(int, input().split())
    arr = list(map(int, input().split()))
    peaks = []
    for x in range(n):
        left = (x-1 < 0) or arr[x-1] < arr[x]
        right = (x+1 >= n) or arr[x+1] < arr[x]
        if left and right:
            peaks.append(x)
    # print(peaks)
    ans = sum([arr[x] for x in peaks])
    for x in range(1, len(peaks)):
        left, right = peaks[x-1], peaks[x]
        mn = n+10
        for i in range(left+1, right):
            mn = min(mn, arr[i])
        ans -= mn
    print(ans)


# https://codeforces.com/contest/1420/problem/C1
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
t = int(input())
for _ in range(t):
    n, q = map(int, input().split())
    arr = list(map(int, input().split()))
    peaks = []
    for x in range(n):
        left = (x-1 < 0) or arr[x-1] < arr[x]
        right = (x+1 >= n) or arr[x+1] < arr[x]
        if left and right:
            peaks.append(x)
    # print(peaks)
    i = 0
    j = 1
    ans = sum([arr[x] for x in peaks])
    while j < len(peaks):
        ans -= min(arr[peaks[i]+1:arr[peaks[j]]])
        j += 1
        i += 1
    print(ans)