#include <bits/stdc++.h>
using namespace std;
const int MAXN = 80 + 5;
int dp[MAXN][MAXN][MAXN][3];
vector<pair<int, int> > adj[MAXN];
int calc(int be, int en, int k, bool which) {
  if (k == 1) return 0;
  if (dp[be][en][k][which] != -1) return dp[be][en][k][which];
  int st = be;
  if (which) st = en;
  int ans = 1e9;
  for (int i = 0; i < (int)adj[st].size(); i++) {
    int u = adj[st][i].first;
    int c = adj[st][i].second;
    if (u < be || u > en) continue;
    if (st == be) {
      int l = calc(be + 1, u, k - 1, true);
      int r = calc(u, en, k - 1, false);
      ans = min(ans, min(l, r) + c);
    } else {
      int l = calc(be, u, k - 1, true);
      int r = calc(u, en - 1, k - 1, false);
      ans = min(ans, min(l, r) + c);
    }
  }
  return dp[be][en][k][which] = ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int v, u, c;
    cin >> v >> u >> c;
    adj[v].push_back(make_pair(u, c));
  }
  memset(dp, -1, sizeof dp);
  int ans = 1e9;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      ans = min(ans, min(calc(i, j, k, 1), calc(i, j, k, 0)));
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
  return 0;
}
