#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
T f_abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int maxn = 85;
const int maxm = 2000 + 5;
struct Node {
  int u, v, w;
} edge[maxm];
int dp[maxn][maxn][maxn][2];
int n, m, k;
int main() {
  int u, v, w;
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) dp[i][j][k][1] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++) dp[i][j][k][0] = 0;
  for (int cnt = k - 1; cnt >= 1; cnt--)
    for (int a = 1; a <= n; a++)
      for (int i = 0; i < m; i++)
        for (int t = 0; t <= 1; t++) {
          u = edge[i].u;
          v = edge[i].v;
          w = edge[i].w;
          if (t == 0) {
            if (a >= u) continue;
            if (v < a || v >= u) continue;
            int x = dp[v][a][cnt + 1][0], y = dp[v][u - 1][cnt + 1][1];
            int cost;
            if (x == -1) {
              if (y == -1)
                cost = -1;
              else
                cost = y;
            } else {
              if (y == -1)
                cost = x;
              else
                cost = min(x, y);
            }
            if (cost != -1) {
              if (dp[u][a][cnt][t] == -1)
                dp[u][a][cnt][t] = cost + w;
              else
                dp[u][a][cnt][t] = min(dp[u][a][cnt][t], cost + w);
            }
          } else {
            if (a <= u) continue;
            if (v <= u || v > a) continue;
            int x = dp[v][u + 1][cnt + 1][0], y = dp[v][a][cnt + 1][1];
            int cost;
            if (x == -1) {
              if (y == -1)
                cost = -1;
              else
                cost = y;
            } else {
              if (y == -1)
                cost = x;
              else
                cost = min(x, y);
            }
            if (cost != -1) {
              if (dp[u][a][cnt][t] == -1)
                dp[u][a][cnt][t] = cost + w;
              else
                dp[u][a][cnt][t] = min(dp[u][a][cnt][t], cost + w);
            }
          }
        }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (dp[i][j][1][0] != -1) ans = min(ans, dp[i][j][1][0]);
      if (dp[i][j][1][1] != -1) ans = min(ans, dp[i][j][1][1]);
    }
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
