#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<vector<int>> adjList;
int OO = 1e9;
int dp[81][81][81][81];
int cost[81][81];
int solve(int l, int cur, int r, int cur_k) {
  if (cur_k == k) return 0;
  int &ret = dp[l][cur][r][cur_k];
  if (ret != -1) return ret;
  ret = OO;
  for (int ch : adjList[cur]) {
    int node = ch;
    int c = cost[cur][ch];
    if (node >= l && node <= r) {
      if (node > cur) ret = min(ret, solve(cur + 1, node, r, cur_k + 1) + c);
      if (node < cur) ret = min(ret, solve(l, node, cur - 1, cur_k + 1) + c);
    }
  }
  return ret;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  memset((dp), (-1), sizeof(dp));
  cin >> n >> k >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cost[i][j] = OO;
  adjList = vector<vector<int>>(n);
  for (int i = 0; i < m; i++) {
    int from, to, c;
    cin >> from >> to >> c;
    --from, --to;
    adjList[from].push_back(to);
    cost[from][to] = min(cost[from][to], c);
  }
  int ans = OO;
  for (int i = 0; i < n; i++) {
    ans = min(ans, solve(0, i, n - 1, 1));
  }
  if (ans == OO) ans = -1;
  cout << ans;
}
