#include <bits/stdc++.h>
using namespace std;
int dp[82][82][82][2];
int gr[82][82], n, k, m;
int go(int l, int r, int baki, bool flag) {
  if (baki == 0) return 0;
  int &ret = dp[l][r][baki][flag];
  if (ret != -1) return ret;
  ret = 0x3f3f3f3f;
  if (flag) {
    for (int i = 1; i <= n; i++) {
      if (gr[l][i] == 0x3f3f3f3f || i <= l || i >= r) continue;
      ret = min(ret, gr[l][i] + go(l, i, baki - 1, 0));
      ret = min(ret, gr[l][i] + go(i, r, baki - 1, 1));
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (gr[r][i] == 0x3f3f3f3f || i <= l || i >= r) continue;
      ret = min(ret, gr[r][i] + go(i, r, baki - 1, 1));
      ret = min(ret, gr[r][i] + go(l, i, baki - 1, 0));
    }
  }
  return ret;
}
int main() {
  int i, j;
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%d", &m);
  memset(dp, -1, sizeof(dp));
  memset(gr, 0x3f3f3f3f, sizeof(gr));
  for (i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d", &u);
    scanf("%d", &v);
    scanf("%d", &c);
    gr[u][v] = min(gr[u][v], c);
  }
  if (k == 1) return printf("0\n"), 0;
  int ans = 0x3f3f3f3f;
  for (i = 1; i <= n; i++) {
    ans = min(ans, go(i, n + 1, k - 1, 1));
    ans = min(ans, go(0, i, k - 1, 0));
  }
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
