#include <bits/stdc++.h>
using namespace std;
int N, K, M;
vector<pair<int, int> > G[82];
bool E[82][82];
int Mn[82][82];
bool vis[82][82][82];
int ans[82][82][82];
int mn = 1e9;
int dfs(int u, int bd, int cnt) {
  if (vis[u][bd][cnt]) return ans[u][bd][cnt];
  vis[u][bd][cnt] = true;
  if (cnt == K) return 0;
  int now = -1;
  int L = min(u, bd), R = max(u, bd);
  for (pair<int, int> e : G[u]) {
    int v = e.first, d = e.second;
    if (v <= L || v >= R) continue;
    int res = dfs(v, L, cnt + 1);
    if (res != -1) now = (now == -1) ? d + res : min(now, d + res);
    res = dfs(v, R, cnt + 1);
    if (res != -1) now = (now == -1) ? d + res : min(now, d + res);
  }
  return ans[u][bd][cnt] = now;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K >> M;
  int u, v, c;
  for (int i = 1; i <= M; i++) {
    cin >> u >> v >> c;
    if (!E[u][v])
      Mn[u][v] = c;
    else
      Mn[u][v] = min(Mn[u][v], c);
    E[u][v] = true;
  }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j && E[i][j]) G[i].push_back(make_pair(j, Mn[i][j]));
  for (int i = 1; i <= N; i++) {
    int res = dfs(i, N + 1, 1);
    if (res != -1) mn = min(mn, res);
    res = dfs(i, 0, 1);
    if (res != -1) mn = min(mn, res);
  }
  cout << ((mn == 1e9) ? -1 : mn) << '\n';
  return 0;
}
