#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[85][85], u, v, c;
int dp[85][85][85];
bool flag[85][85][85];
int get_answ(int l, int r, int k) {
  if (k == 0) return 0;
  if (flag[l][r][k]) return dp[l][r][k];
  flag[l][r][k] = 1;
  dp[l][r][k] = (1 << 28);
  for (int i = min(l, r) + 1; i < max(l, r); i++)
    if (a[l][i] != (1 << 28)) {
      dp[l][r][k] =
          min(dp[l][r][k],
              min(get_answ(i, l, k - 1), get_answ(i, r, k - 1)) + a[l][i]);
    }
  return dp[l][r][k];
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = (1 << 28);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    a[u][v] = min(a[u][v], c);
  }
  int answ = get_answ(0, n + 1, k);
  if (answ != (1 << 28))
    printf("%d", answ);
  else
    printf("-1");
}
