#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int64_t n, k;
  cin >> n >> k;
  int64_t m;
  cin >> m;
  vector<vector<pair<int64_t, int64_t>>> edges(n);
  for (int64_t i = 0; i < m; ++i) {
    int64_t u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    if (u == v) continue;
    edges[u].push_back({v, c});
  }
  vector<vector<vector<int64_t>>> dp(
      n, vector<vector<int64_t>>(n, vector<int64_t>(k + 1, INF)));
  for (int64_t start = 0; start < n; ++start) {
    for (int64_t end = 0; end < n; ++end) {
      dp[start][end][1] = 0;
    }
  }
  for (int64_t l = 2; l <= k; ++l) {
    for (int64_t dist = 1; dist < n; ++dist) {
      for (int64_t start = 0; start < n; ++start) {
        int64_t end = start + dist;
        if (end >= 0 && end < n) {
          for (auto nxt : edges[start]) {
            if (nxt.first <= end && nxt.first > start) {
              dp[start][end][l] =
                  min(dp[start][end][l],
                      min(dp[nxt.first][end][l - 1] + nxt.second,
                          dp[nxt.first][start + 1][l - 1] + nxt.second));
            }
          }
        }
        end = start - dist;
        if (end >= 0 && end < n) {
          for (auto nxt : edges[start]) {
            if (nxt.first >= end && nxt.first < start) {
              dp[start][end][l] =
                  min(dp[start][end][l],
                      min(dp[nxt.first][end][l - 1] + nxt.second,
                          dp[nxt.first][start - 1][l - 1] + nxt.second));
            }
          }
        }
      }
    }
  }
  int64_t ans = INF;
  for (int64_t start = 0; start < n; ++start) {
    for (int64_t end = 0; end < n; ++end) {
      ans = min(ans, dp[start][end][k]);
    }
  }
  if (ans == INF) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << '\n';
  return 0;
}
