#include <bits/stdc++.h>
using namespace std;
const int N = 80;
int adj[N + 2][N + 2];
int res[N + 2][N + 2][N + 2];
int inf;
void solve(int a, int b, int k) {
  int& ans = res[a][b][k];
  if (ans == -1) {
    ans = inf;
    int shift = (a < b) ? 1 : -1;
    for (int i = a + shift; i != b + shift; i += shift) {
      int c = adj[a][i];
      if (c != inf) {
        if (res[i][b][k - 1] == -1) solve(i, b, k - 1);
        if (res[i][a + shift][k - 1] == -1) solve(i, a + shift, k - 1);
        int left = res[i][a + shift][k - 1];
        int right = res[i][b][k - 1];
        if (left != inf && ans > c + left) {
          ans = c + left;
        }
        if (right != inf && ans > c + right) {
          ans = c + right;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(adj, 0, sizeof(adj));
  int n, nk;
  cin >> n >> nk;
  inf = 1e6;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) adj[i][j] = inf;
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u][v] = min(adj[u][v], c);
  }
  if (nk == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= nk; ++k) {
        res[i][j][k] = -1;
      }
      res[i][j][1] = 0;
    }
  }
  for (int k = 2; k <= nk; ++k) {
    for (int i = 1; i <= N; ++i) {
      res[i][i][k] = inf;
    }
  }
  int ans = inf;
  for (int i = 1; i <= n; ++i) {
    solve(i, n, nk);
    solve(i, 1, nk);
    if (res[i][n][nk] != inf) ans = min(ans, res[i][n][nk]);
    if (res[i][1][nk] != inf) ans = min(ans, res[i][1][nk]);
  }
  if (ans == inf) ans = -1;
  cout << ans << endl;
  return 0;
}
