Bankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office.

The crossroads are connected with m oriented bicycle lanes (the i-th lane goes from crossroad ui to crossroad vi), the difficulty of each of the lanes is known.

Oleg the bank client wants to gift happiness and joy to the bank employees. He wants to visit exactly k offices, in each of them he wants to gift presents to the employees.

The problem is that Oleg don't want to see the reaction on his gifts, so he can't use a bicycle lane which passes near the office in which he has already presented his gifts (formally, the i-th lane passes near the office on the x-th crossroad if and only if min(ui, vi) < x < max(ui, vi))). Of course, in each of the offices Oleg can present gifts exactly once. Oleg is going to use exactly k - 1 bicycle lane to move between offices. Oleg can start his path from any office and finish it in any office.

Oleg wants to choose such a path among possible ones that the total difficulty of the lanes he will use is minimum possible. Find this minimum possible total difficulty.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 80) — the number of crossroads (and offices) and the number of offices Oleg wants to visit.

The second line contains single integer m (0 ≤ m ≤ 2000) — the number of bicycle lanes in Bankopolis.

The next m lines contain information about the lanes.

The i-th of these lines contains three integers ui, vi and ci (1 ≤ ui, vi ≤ n, 1 ≤ ci ≤ 1000), denoting the crossroads connected by the i-th road and its difficulty.

Output

In the only line print the minimum possible total difficulty of the lanes in a valid path, or -1 if there are no valid paths.

Examples

Input

7 4
4
1 6 2
6 2 2
2 4 2
2 7 1


Output

6


Input

4 3
4
2 1 2
1 3 2
3 4 2
4 1 1


Output

3

Note

In the first example Oleg visiting banks by path 1 → 6 → 2 → 4.

Path 1 → 6 → 2 → 7 with smaller difficulity is incorrect because crossroad 2 → 7 passes near already visited office on the crossroad 6.

In the second example Oleg can visit banks by path 4 → 1 → 3.
import java.util.*;
import java.io.*;

public class ProbD {
	public static void main(String[] args){
		ProbD sol = new ProbD();
		sol.start();
	}

	StringBuffer printstr;
	String _readerstr;
	BufferedReader rdr;
	HashSet<Integer> debug_number_set;
	int[] debug_code;

	public void print(Object o){ print(o, 0); }
	public void print(Object o, int debug_number){
		if(debug_number_set.contains(debug_number)) System.out.print(o);
	}
	public void println() { print("\n", 0); }
	public void println(Object o) { println(o, 0); }
	public void println(Object o, int debug_number){ print(o+"\n", debug_number); }

	public void bufp(Object o){ printstr.append(o); }
	public void bufpl(Object o){ printstr.append(o).append('\n'); }
	public void bufpl() { printstr.append('\n'); }
	public void bufp(char[] c, int offset, int len){ printstr.append(c, offset, len); }
	public void bufpl(char[] c, int offset, int len){ printstr.append(c, offset, len).append('\n'); }
	
	public Integer readInt(){
		try{
			if(_readerstr==null) _readerstr = rdr.readLine();
		}
		catch(Exception e){ return null; }
		String[] s = _readerstr.split(" ", 2);
		if(s.length==1) _readerstr = null;
		else _readerstr = s[1];
		try{
			return Integer.parseInt(s[0]);
		}
		catch(Exception e){}
		return readInt();
	}
	
	public Long readLong(){
		try{
			if(_readerstr==null) _readerstr = rdr.readLine();
		}
		catch(Exception e){ return null; }
		String[] s = _readerstr.split(" ", 2);
		if(s.length==1) _readerstr = null;
		else _readerstr = s[1];
		try{
			return Long.parseLong(s[0]);
		}
		catch(Exception e){}
		return readLong();
	}
	
	public Double readDouble(){
		try{
			if(_readerstr==null) _readerstr = rdr.readLine();
		}
		catch(Exception e){ return null; }
		String[] s = _readerstr.split(" ", 2);
		if(s.length==1) _readerstr = null;
		else _readerstr = s[1];
		try{
			return Double.parseDouble(s[0]);
		}
		catch(Exception e){}
		return readDouble();
	}
	
	public String readStr(){
		try{
			if(_readerstr==null) _readerstr = rdr.readLine();
		}
		catch(Exception e){ return null; }
		String[] s = _readerstr.split(" ", 2);
		if(s.length==1) _readerstr = null;
		else _readerstr = s[1];
		return s[0];
	}
	
	public String readLine(){
		try{
			if(_readerstr==null) _readerstr = rdr.readLine();
		}
		catch(Exception e){ return null; }
		String ret = _readerstr;
		_readerstr = null;
		return ret;
	}

	public void start(){
		debug_code = new int[] {0,1,2,3,4,5};
		initiate_the_entire_program();
		
		submit();
		
		System.out.println(printstr);
		System.out.flush();
	}
	
	public void initiate_the_entire_program(){
		printstr = new StringBuffer();
		_readerstr = null;
		try{
			rdr = new BufferedReader(new InputStreamReader(System.in));
		}
		catch(Exception e){ println(e); }
		debug_number_set = new HashSet();
		for(int i : debug_code) debug_number_set.add(i);
	}
	
//	class PathNode{
//		int begin;
//		int end;
//		int cost;
//		public PathNode(int b, int e, int c) {begin=b;end=e;cost=c;}
//		public int hashCode() { return begin * 100 + end; }
//	}
	
	public void submit(){
		Integer n = readInt();
		Integer k = readInt();
		Integer m = readInt();
		int[][] crossroads = new int[m][3];
		for(int i=0;i<m;i++) for(int j=0;j<3;j++) 
			crossroads[i][j] = readInt() - (j==2?0:1);
		
		int ret = findLeastDifficulty(n, k, m, crossroads);
		
		bufpl(ret);
	}
	
	public int findLeastDifficulty(int n, int k, int m, int[][] roads){
		int[][][] dp = new int[n][n][k];
		//dp[a][b][i-1] = the minimum difficulty if we want the itinerary to
		//	start at crossroad a; and
		//	reach i banks; and
		//	all the k banks reached are within crossroads [a..b] or [b..a]
		//	i.e., if a bank among the i banks is at crossroad x, then (x-a)*(x-b)<=0.
		//dp[a][b][i-1] = -1 if such an itinerary does not exist
		
		int[][] difficulties = new int[n][n];
		//difficulties[i][j] = the minimum difficulty from i to j in a single travel,
		//	or -1 if impossible
		
		for(int i=0;i<n;i++) Arrays.fill(difficulties[i], -1);
		for(int a=0;a<n;a++) for(int b=0;b<n;b++) for(int c=0;c<n;c++) Arrays.fill(dp[a][b], -1);
		
		for(int[] road : roads){
			int i = road[0];
			int j = road[1];
			int d = road[2];
			if(difficulties[i][j]==-1 || difficulties[i][j]>d) difficulties[i][j] = d;
		}
		
		for(int a=0;a<n;a++) for(int b=0;b<n;b++) dp[a][b][0] = 0;
		
		for(int i=1;i<k;i++){
			//find all dp[a][b][i];
			for(int a=0;a<n;a++) for(int t=0;t<n;t++){
				//t is the first stop of the itinerary
				if(a==t || difficulties[a][t]==-1) continue;
				
				if(t<a) for(int b=0;b<a;b++){
					if(dp[t][b][i-1]==-1) continue;
					int tmp = difficulties[a][t] + dp[t][b][i-1];
					int bar = Math.min(b,t);
					if(dp[a][bar][i]==-1 || dp[a][bar][i]>tmp) dp[a][bar][i] = tmp;
				}
				else for(int b=a+1;b<n;b++){
					if(dp[t][b][i-1]==-1) continue;
					int tmp = difficulties[a][t] + dp[t][b][i-1];
					int bar = Math.max(b, t);
					if(dp[a][bar][i]==-1 || dp[a][bar][i]>tmp) dp[a][bar][i] = tmp;
				}
				
//				for(int tmpb=0;tmpb<=t;tmpb++) for(int tmpc=t;tmpc<n;tmpc++){
//					if(dp[t][b][c][i-1]==-1) continue;
//					int tmp = difficulties[a][t] + dp[t][tmpb][c][i-1];
//					if(dp[a][b][c][i]==-1 || dp[a][b][c][i]>tmp) dp[a][b][c][i] = tmp;
//				}
				
			}
		}
		
		int ret = -1;
		for(int a=0;a<n;a++) for(int b=0;b<n;b++){
			if(dp[a][b][k-1]==-1) continue;
			if(ret==-1 || dp[a][b][k-1]<ret) ret = dp[a][b][k-1];
		}
		return ret;
		
		
	}
	
	/*
	7 4
	4
	1 6 2
	6 2 2
	2 4 2
	2 7 1
	*/
}