#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T& a, const T& b) {
  return a < b ? (a = b, true) : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  return b < a ? (a = b, true) : false;
}
int N, M, K;
int edge[81][81];
int memo[81][81][2][81];
const int INF = 1e9;
int rec(int l, int r, int isRight, int k) {
  if (memo[l][r][isRight][k] != -1) return memo[l][r][isRight][k];
  if (k == K) return 0;
  if (r == l) return INF;
  int& res = memo[l][r][isRight][k];
  res = INF;
  if (isRight == 0) {
    for (int i = l + 1; i <= r; i++)
      if (edge[l][i] < INF) {
        chmin(res, rec(l + 1, i, 1, k + 1) + edge[l][i]);
        chmin(res, rec(i, r, 0, k + 1) + edge[l][i]);
      }
  } else {
    for (int i = l; i <= r - 1; i++)
      if (edge[r][i] < INF) {
        chmin(res, rec(l, i, 1, k + 1) + edge[r][i]);
        chmin(res, rec(i, r - 1, 0, k + 1) + edge[r][i]);
      }
  }
  return res;
}
int main() {
  scanf("%d%d%d", &N, &K, &M);
  fill(edge[1], edge[N + 1], INF);
  for (int i = (int)(0); i < (int)(M); i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    chmin(edge[u][v], c);
  }
  memset(memo, -1, sizeof(memo));
  int ans = INF;
  for (int i = (int)(1); i < (int)(N + 1); i++) {
    chmin(ans, rec(1, i, 1, 1));
    chmin(ans, rec(i, N, 0, 1));
  }
  printf("%d\n", ans != INF ? ans : -1);
  return 0;
}
