#include <bits/stdc++.h>
using namespace std;
const int N = 88;
const long long INF = 1.01e9;
int n, k;
vector<pair<int, int>> e[N];
int dp[N][N][N];
void upd(int& A, int B) { A = min(A, B); }
int main() {
  scanf("%d%d", &n, &k);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int v, u, c;
    scanf("%d%d%d", &v, &u, &c);
    v--;
    u--;
    e[v].push_back({u, c});
  }
  memset(dp, 63, sizeof dp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j][1] = 0;
    }
  }
  for (int len = 1; len < n; len++) {
    for (int i = 0; i + len < n; i++) {
      int v = i;
      int u = i + len;
      for (int tt = 0; tt < 2; tt++) {
        for (int t = 2; t <= k; t++) {
          for (auto x : e[v]) {
            if (min(v, u) < x.first && x.first < max(v, u)) {
              if (v < x.first)
                upd(dp[v][u][t], dp[x.first][v + 1][t - 1] + x.second);
              else
                upd(dp[v][u][t], dp[x.first][v - 1][t - 1] + x.second);
              upd(dp[v][u][t], dp[x.first][u][t - 1] + x.second);
            }
            if (x.first == u) {
              if (v < u)
                upd(dp[v][u][t], dp[x.first][v + 1][t - 1] + x.second);
              else
                upd(dp[v][u][t], dp[x.first][v - 1][t - 1] + x.second);
            }
          }
        }
        swap(v, u);
      }
    }
  }
  int answer = INF;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      answer = min(answer, dp[i][j][k]);
      answer = min(answer, dp[i][j][k]);
    }
  if (answer == INF) {
    puts("-1");
  } else {
    cout << answer << endl;
  }
  return 0;
}
