#include <bits/stdc++.h>
void read(int &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
void read(long long &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
using namespace std;
const int inf = 0x3f3f3f3f, maxn = 81;
int n, k, m, mp[maxn][maxn], dp[maxn][maxn][maxn][maxn];
int DP(int pos, int l, int r, int remain) {
  if (~dp[pos][l][r][remain]) return dp[pos][l][r][remain];
  if (remain == 1) return dp[pos][l][r][remain] = 0;
  int ret = inf;
  for (int i = l + 1; i <= (int)r - 1; i++)
    if (mp[pos][i] != inf) {
      int nl = l, nr = r;
      if (i > pos)
        nl = pos;
      else
        nr = pos;
      ret = min(ret, DP(i, nl, nr, remain - 1) + mp[pos][i]);
    }
  return dp[pos][l][r][remain] = ret;
}
int main() {
  read(n), read(k), read(m);
  memset(mp, 0x3f, sizeof(mp));
  for (int i = 1; i <= (int)m; i++) {
    int u, v, w;
    read(u), read(v), read(w);
    mp[u][v] = min(mp[u][v], w);
  }
  memset(dp, -1, sizeof(dp));
  int ans = inf;
  for (int i = 1; i <= (int)n; i++) ans = min(ans, DP(i, 0, n + 1, k));
  printf("%d\n", ans == inf ? -1 : ans);
  return 0;
}
