#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1000;
const long long INF64 = 1e15 + 1000;
const int M = 2 * 100 * 1000 + 100;
const int N = 80;
const int MOD = 1e6 + 3;
const double EPS = 1e-9;
const double PI = 3.14159265359;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
vector<pair<int, int> > g[N];
int dp[N][N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int m;
  cin >> m;
  for (int i = 0; i < int(m); ++i) {
    int v, u, c;
    cin >> v >> u >> c;
    v--;
    u--;
    g[v].push_back({u, c});
  }
  for (int i = 0; i < int(N); ++i) {
    for (int j = 0; j < int(N); ++j) {
      for (int k = 0; k < int(N); ++k) {
        dp[i][j][k] = INF;
      }
    }
  }
  for (int i = 0; i < int(n); ++i) {
    for (int j = 0; j < int(n); ++j) {
      dp[i][j][0] = 0;
    }
  }
  int ans = INF;
  for (int cnt = 0; cnt < int(k); ++cnt) {
    for (int v = 0; v < int(n); ++v) {
      for (int a = 0; a < int(n); ++a) {
        if (dp[v][a][cnt] == INF) continue;
        for (auto to_v : g[v]) {
          int to = to_v.first, w = to_v.second;
          if (to >= min(v, a) && to <= max(v, a)) {
            if (to < v) {
              dp[to][a][cnt + 1] = min(dp[to][a][cnt + 1], w + dp[v][a][cnt]);
              dp[to][v - 1][cnt + 1] =
                  min(dp[to][v - 1][cnt + 1], w + dp[v][a][cnt]);
            } else if (to > v) {
              dp[to][v + 1][cnt + 1] =
                  min(dp[to][v + 1][cnt + 1], w + dp[v][a][cnt]);
              dp[to][a][cnt + 1] = min(dp[to][a][cnt + 1], w + dp[v][a][cnt]);
            }
          }
        }
        if (cnt == k - 1) {
          ans = min(ans, dp[v][a][cnt]);
        }
      }
    }
  }
  cout << (ans == INF ? -1 : ans) << '\n';
}
