#include <bits/stdc++.h>
const double pi = (double)(2.0 * acos(0.0));
const int inf = 1 << 30;
const double eps = 1E-12;
const double e = exp(1.0);
const int sz = 76 + 5;
using namespace std;
const long long int mod = 1000000000 + 7;
int n, m;
int dp[sz][sz][2][sz], cost[sz][sz];
int rec(int l, int r, bool lr, int k) {
  if (k < 1) return 0;
  if (r - l < 2) return inf;
  int &res = dp[l][r][lr][k];
  if (res != -1) return res;
  res = inf;
  int u = (lr ? l : r);
  for (int i = l + 1; i < r; i++) {
    if (cost[u][i] < 1) continue;
    res = min(res, cost[u][i] + rec(l, i, 0, k - 1));
    res = min(res, cost[u][i] + rec(i, r, 1, k - 1));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int k, u, v, c;
  cin >> n >> k;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    if (cost[u][v] == 0)
      cost[u][v] = c;
    else
      cost[u][v] = min(cost[u][v], c);
  }
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  memset(dp, -1, sizeof(dp));
  int res = inf;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || cost[i][j] < 1) continue;
      res = min(res, cost[i][j] + rec(min(i, j), max(i, j), (j < i), k - 2));
      if (i < j)
        res = min(res, cost[i][j] + rec(j, n + 1, 1, k - 2));
      else
        res = min(res, cost[i][j] + rec(0, j, 0, k - 2));
    }
  }
  if (res < inf)
    cout << res << endl;
  else
    cout << -1 << endl;
  return 0;
}
