#include <bits/stdc++.h>
using namespace std;
const int maxn = 82;
int n, m, k, w, G[maxn][maxn], d[maxn][maxn][maxn][maxn], st, en, mins, ans;
int dfs(int st, int step, int l, int r) {
  if (d[l][r][st][step] != -1) return d[l][r][st][step];
  if (step == 1) {
    return d[l][r][st][step] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (G[st][i] != 0x3f3f3f3f && i > l && i < r) {
      int l1 = l, r1 = r;
      if (i > st)
        l1 = st;
      else
        r1 = st;
      int ans = dfs(i, step - 1, l1, r1);
      if (d[l][r][st][step] > 0) {
        d[l][r][st][step] = min(ans + G[st][i], d[l][r][st][step]);
      } else
        d[l][r][st][step] = ans + G[st][i];
    }
  }
  if (d[l][r][st][step] > 0) return d[l][r][st][step];
  return 0x3f3f3f3f;
}
int main() {
  while (cin >> n >> k >> m) {
    memset(d, -1, sizeof(d));
    memset(G, 0x3f3f3f3f, sizeof(G));
    mins = 0x3f3f3f3f;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d", &st, &en, &w);
      G[st][en] = min(G[st][en], w);
    }
    for (int i = 1; i <= n; i++) {
      mins = min(mins, dfs(i, k, 0, n + 1));
    }
    if (mins >= 0x3f3f3f3f) mins = -1;
    printf("%d\n", mins);
  }
  return 0;
}
