#include <bits/stdc++.h>
using namespace std;
int n, k;
int dp[85][85][85];
vector<pair<int, int> > adj[100];
int solve(int u, int v, int d) {
  if (d == k) return 0;
  if (dp[u][v][d] != -1) return dp[u][v][d];
  int l = min(u, v);
  int r = max(u, v);
  int res = 1e9;
  for (int i = 0; i < adj[u].size(); i++) {
    int x = adj[u][i].first;
    int y = adj[u][i].second;
    if (l == 0)
      res = min(res, solve(x, u, d + 1) + y);
    else {
      if (x < l) res = min(res, solve(x, r, d + 1) + y);
      if (x > r) res = min(res, solve(x, l, d + 1) + y);
    }
  }
  return dp[u][v][d] = res;
}
int main() {
  int i, j;
  cin >> n >> k;
  int m;
  cin >> m;
  while (m--) {
    int u, v, e;
    cin >> u >> v >> e;
    adj[v].push_back(make_pair(u, e));
  }
  memset(dp, -1, sizeof(dp));
  int res = 1e9;
  for (i = 1; i <= n; i++) {
    res = min(res, solve(i, 0, 1));
  }
  if (res == 1e9) res = -1;
  cout << res;
  return 0;
}
