#include <bits/stdc++.h>
using namespace std;
const int N = 85;
vector<pair<int, int> > g[N];
int dp[N][N][N][N];
int n, k;
int solve(int l, int r, int node, int rk) {
  if (!rk) return 0;
  int &ret = dp[l][r][node][rk];
  if (ret != -1) return ret;
  ret = 1e8;
  if (rk == k) {
    for (int i = 1; i <= n; i++) {
      ret = min(ret, solve(0, n + 1, i, k - 1));
    }
  } else {
    for (int i = 0; i < g[node].size(); i++) {
      int u = g[node][i].first;
      int c = g[node][i].second;
      if (u >= r || u <= l) continue;
      if (u > node)
        ret = min(ret, solve(node, r, u, rk - 1) + c);
      else
        ret = min(ret, solve(l, node, u, rk - 1) + c);
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  int m;
  cin >> m;
  for (int i = 0, u, v, c; i < m; i++) {
    cin >> u >> v >> c;
    g[u].push_back(make_pair(v, c));
  }
  memset(dp, -1, sizeof dp);
  int ans = solve(0, 0, 0, k);
  if (ans >= 1e8) ans = -1;
  cout << ans << endl;
  return 0;
}
