Problem: 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.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
int n, k, m, u, v, c;
vector<int> graph[85];
int cost[85][85], dp[85][85][85][85];
bool visited[85][85][85][85];
int go(int now, int l, int r, int cnt) {
  if (cnt == 0) return 0;
  if (l > r) return 1e9;
  if (visited[now][l][r][cnt]) return dp[now][l][r][cnt];
  visited[now][l][r][cnt] = true;
  int ret1 = 1e9, ret2 = 1e9;
  for (auto v : graph[now]) {
    if (v >= l && v <= r) {
      ret1 = min(ret1, cost[now][v] + go(v, v + 1, r, cnt - 1));
      ret2 = min(ret2, cost[now][v] + go(v, l, v - 1, cnt - 1));
    }
  }
  return dp[now][l][r][cnt] = min(ret1, ret2);
}
int main() {
  int test, cases = 1;
  cin >> n >> k >> m;
  memset(cost, 63, sizeof(cost));
  int inf = cost[0][0];
  for (int i = (0); i < (m); i++) {
    cin >> u >> v >> c;
    if (cost[u][v] != inf) {
      cost[u][v] = min(cost[u][v], c);
      continue;
    }
    graph[u].push_back(v);
    cost[u][v] = c;
  }
  int ans = 1e9;
  memset(visited, false, sizeof(visited));
  for (int i = (1); i < (n + 1); i++) {
    ans = min(ans, go(i, 1, i - 1, k - 1));
    ans = min(ans, go(i, i + 1, n, k - 1));
  }
  if (ans == 1e9)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}