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 *u*<sub class="lower-index">*i*</sub> to crossroad *v*<sub class="lower-index">*i*</sub>), 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*(*u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub>) &lt; *x* &lt; *max*(*u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub>))). 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.
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 *u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub> and *c*<sub class="lower-index">*i*</sub> (1 ≤ *u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub> ≤ *n*, 1 ≤ *c*<sub class="lower-index">*i*</sub> ≤ 1000), denoting the crossroads connected by the *i*-th road and its difficulty.
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.
7 4
4
1 6 2
6 2 2
2 4 2
2 7 1
6
4 3
4
2 1 2
1 3 2
3 4 2
4 1 1
3
3 2
10
2 3 290
3 1 859
3 1 852
1 2 232
1 2 358
2 1 123
1 3 909
2 1 296
1 3 119
1 2 584
119
3 3
4
1 2 545
1 3 716
3 1 3
2 3 338
548
5 3
20
5 2 515
4 1 865
3 4 570
1 5 371
3 1 420
5 2 464
4 3 130
4 1 381
1 2 702
5 1 97
5 2 402
5 2 314
1 4 272
3 1 505
5 4 662
2 3 893
1 3 20
4 2 601
1 3 4
4 2 474
101
5 5
20
2 5 174
4 3 496
5 2 103
2 1 345
2 4 942
3 5 131
3 2 451
5 2 299
2 4 285
4 5 241
4 5 706
2 1 639
1 5 94
1 2 844
3 4 194
2 4 812
2 5 566
3 5 293
3 4 356
2 5 717
978
5 5
10
2 4 420
4 5 974
5 1 910
1 3 726
1 2 471
5 2 94
3 2 307
2 5 982
5 4 848
3 5 404
-1
3 2
4
2 3 716
3 2 239
3 2 646
3 2 39
39
5 4
4
5 4 614
4 1 177
1 3 66
5 2 43
857
10 4
10
1 4 662
4 7 555
7 9 172
1 8 481
8 10 609
1 2 705
1 10 225
8 2 939
2 10 329
6 10 477
1389
10 7
50
4 7 655
7 3 220
3 5 15
5 10 811
10 1 490
1 2 800
7 10 200
1 5 377
1 4 656
6 4 432
3 7 563
1 8 122
2 9 777
3 2 157
5 8 912
9 8 496
9 2 740
3 2 201
6 7 653
1 7 554
6 9 660
3 2 622
6 10 227
9 1 42
2 6 346
2 7 944
3 10 654
5 2 501
1 6 786
3 8 306
6 1 998
6 2 581
10 1 843
10 9 993
10 9 93
2 9 770
1 5 89
1 7 761
6 1 387
7 1 24
5 9 922
1 8 480
9 7 814
4 3 682
9 3 73
9 6 436
4 1 685
10 8 46
8 2 725
4 1 892
1760
6 4
10
2 5 609
5 6 805
6 4 814
5 6 322
4 3 689
4 6 30
2 1 949
2 1 650
2 4 217
4 2 362
1826
1 1
0
0
/*
                                                                                                     
                                             `-:://:::-                                             
                                           `//:-------:/:`                                          
                                          .+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .o:--...```..---+/`                                        
                                       `/y+o/---....---:+o.                                         
                                   `...````-os+/:---:/+o/--.`                                       
              `-/+++++/:.      `...`       :h+d+oooo+/+-`   ...                                     
            `/++//:::://++-`....`         -.`//````````:`     `..`                                  
           `o+/::------://o/`           `-` -.          -`       `..`                               
 `---.-o/:./o/::-..``..-ЗАПУСКАЕМ      ..  ..            -`        `...       ``..``                
  `....o+:-++/:--.```..-://s.        `-`  .-              -`          `-o: .-//::::/:-`             
          `:s+/:--....-::/+s-`      .-   `-                -`           -///:--------:/:`           
           ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ        `+:--........--:/`          
            .:ooo+++++osso-`    `.:-...`/` ./::-------:/:`   -`         :+--..``````.--:+:...-+:-`  
             `.-/+++++/+-.-`    -.   ``:so:/:--.......--:+`  `-```````o+/+--..`````..--:o/-..:s+:.  
                 ```````:``.. `-`     -` `+:--..`````..--/+-.../.`````..-o:--.......---/o.    `     
                        `:  `:-      -.  .o:--..`` ``..--:o`   `-`      `:o+:--------:+o-`          
                         `-`-...    ..   .o/--...```..--:+/`    `-`     `oy/so/////++o/.`           
                          -/`  `-` `- ``+s/o/:---...---:++.      `-`   .-../d://///:-.`             
                `.---..``-..-    .-/..`````-oo+/:::::/+o+-        `-``-`  `-.  ````                 
             `:++++/+++++-  ..``.-/:`      /y-:/++o++/:.`..`       ./.   `-                         
            -++/::::::://+/..:-``:` ..   `-.`  ```.```    `..`   `..`-` `-                          
       ``  -o//:--....-::/++` -.-`   `-`.-`                 `..`..`  `-.-                           
  -----ss+:++/:--.```..-://s.  /.     `::                    `-:.     ./`                           
  `````/:..+o/::-..``.--:/+s. ..-`   `-``-`                 ..` `-`  `-`-`                          
          `-s+/::-----::/+oo---``-` ..    .:-    ```      .-`     .-.-  `-`                         
           `:oo+//::://+os/..:`..-/:`      :y.-:::::::.`.-`        ./-`  `-`                        
            `./+oooooooo+/.`-    .-:...`.. .//:-------://`        `- `..` `:.                       
              ``.-::::-.``-/`  `-` `-  `oo:+:--.......--:/`      `-    `.:--h.``..```               
                          -.-`.-    .-   `+:--..`````..--//`    `-       /s-//::::::::.             
                         -` `/-      ..  .o:--..`` ``..--:o.```.-        `//:--------://`           
                        -` .-`.-`     -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`          
                       ..`-.   `-.   ``:os:o/:---...---:++.  `-     ``///+:-..``````.--:+-````-.`   
              `.:///////.-`      .:-..` -``-+o+/:::::/+o/.  `-         `:+:-..`````..--:o/:--/ys+-  
            `-++///////+o/. ``....`-.    :` `.:++++++/:.`  .-           -o/---......---/o.   `.`    
           `++//:-----::/+o:..`     .-`   :    ```````    .-           `+so+:--------:++-`          
  `````:-``:o/::-..`..--:/+o`         -.  `-             .-          `../../+o+////+o+:.`           
  -----syo/o+/:--.```..-://s.          .-` `-           .-        `...     ``-:////:-``             
       .` `/s//:--....-::/+s.            -. `-`        .-       `..`                                
           .+o+/:::--:://+s/-..`          .::+y  ```  .-     `..`                                   
            ./oo++////+oso-`   `....       :y-+:::::::/`   ...                                      
             `.:+oooooo/-`         `....-. .//:-------:/:-.`                                        
                ``...``                 /+:+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .+/--...```..--:+/`                                        
                                         `-o/:---...---:++.                                         
                                          `-+o+/:---:/+o/.                                          
                                            `.:+oooo+/-.`                                           
                                               ``````                                               
*/


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <ostream>
#include <istream>
#include <typeinfo>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <limits>
#include <fstream>
#include <array>
#include <list>
#include <bitset>
#include <functional>

#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define umap unordered_map
#define uset unordered_set
#define rt return 0;
#define elif else if
#define len(v) ((int)v.size())


using namespace std;

char string_in_buffer[(int)260];


void fast_scan(int &x) { scanf("%d", &x); }
void fast_scan(long long &x) { scanf("%lld", &x); }
void fast_scan(unsigned long long &x) { scanf("%llu", &x); }
void fast_scan(double &x) { scanf("%lf", &x); }
void fast_scan(long double &x) { scanf("%Lf", &x); }
void fast_scan(char &x) { 
	scanf("%c", &x); 
	if (x == '\n') {
		fast_scan(x);
	}
}
void fast_scan(string &x) {
	scanf("%s", string_in_buffer);
	x = string(string_in_buffer);
}

template<class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
	fast_scan(p.first);
	fast_scan(p.second);
}

template <class T>
void fast_scan(vector<T> &v) {
	for (auto &x : v) fast_scan(x);
}

void fast_print(const int &x) { printf("%d", x); }
void fast_print(const long long &x) { printf("%lld", x); }
void fast_print(const unsigned long long &x) { printf("%llu", x); }
void fast_print(const double &x) { printf("%.15lf", x); }
void fast_print(const long double &x) { printf("%.15Lf", x); }
void fast_print(const char &x) { printf("%c", x); };
void fast_print(const string &x) { printf("%s", x.c_str());}

template<class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
	fast_print(p.first);
	fast_print(' ');
	fast_print(p.second);
}

template <class T>
void fast_print(const vector<T> &v) {
	if (v.empty()) return;
	fast_print(v[0]);
	for (int i = 1; i < v.size(); i++) {
		fast_print(" ");
		fast_print(v[i]);
	}
}

template <class T>
void fast_print(const vector<vector<T>> &v) {
	if (v.empty()) return;
	fast_print(v[0]);
	for (int i = 1; i < v.size(); i++) {
		fast_print("\n");
		fast_print(v[i]);
	}
}



using namespace std;


namespace smart_io {
	string print_start = "";
	string sep = " ";
	bool first_print = false;

	void precall_print() {
		fast_print(print_start);
		print_start = "\n";
		first_print = true;
	}
} //namespace smart_io


template <class T>
ostream &operator,(ostream &os, const T &object) {
	if (!smart_io::first_print) {
		fast_print(smart_io::sep);
	} else {
		smart_io::first_print = false;
	}
	fast_print(object);
	return os;
}

template <class T>
istream &operator,(istream &is, T &object) {
	fast_scan(object);
	return is;
}

namespace typedefs {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int, int> pii;
}

namespace numbers_operation {
	template<class T>
	T floor_mod(T a, T b) {
		if (a % b == 0) return 0;
		if (a >= 0 && b >= 0) return a % b;
		if (a <= 0 && b <= 0) return a % b;
		return abs(b) - (abs(a) % abs(b));
	}
}

using namespace numbers_operation;
using namespace typedefs;

#define print    \
smart_io::precall_print(); \
cout,

#define scan cin,

int n, k, m;
vector<vector<pii>> vertices;

vector<vector<vector<map<int, int>>>> mem;

int dp(int left, int right, int from, int k) {
	if (mem[left][right][k].find(from) != mem[left][right][k].end()) return mem[left][right][k][from];
	if (k == 0) return 0;
	int _min = 1e9;
	for (pii sub : vertices[from]) {
		if (left <= sub.first && sub.first < right) {
			_min = min(_min, dp(left, sub.first + 1, sub.first, k - 1) + sub.second);
			_min = min(_min, dp(sub.first, right, sub.first, k - 1) + sub.second);
		}
	}
	return mem[left][right][k][from] = _min;
}

signed main(signed argc, char *argv[]) {
	scan n, k, m;
	vertices.resize(n);
	mem.resize(n + 1, vector<vector<map<int, int>>>(n + 1, vector<map<int, int>>(n + 1)));
	for (int i = 0; i < m; i++) {
		int a, b, w;
		scan a, b, w;
		a--;b--;
		vertices[a].pb({b, w});
	}
	int _min = 1e9;
	for (int i = 0; i < n; i++) {
		_min = min(_min, dp(0, n, i, k - 1));
	}

	if (_min == 1e9) {
		print -1;
	} else {
		print _min;
	}

}