#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int m;
  cin >> m;
  struct Edge {
    int source, target, value;
  };
  auto adjacency_list = vector<vector<Edge>>(n + 1);
  for (auto i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    adjacency_list[u].push_back({u, v, c});
  }
  const auto infinity = numeric_limits<int>::max() - 1000;
  auto dp = new int[81][2][82][80]{};
  memset(dp, -1, sizeof(int) * 81 * 2 * 82 * 80);
  const function<int(int, bool, int, int)> f =
      [&](const int v, const bool direction, const int bound, const int k) {
        if (k == 0) return 0;
        auto& result = dp[v][direction][bound][k];
        if (result == -1) {
          result = infinity;
          for (const auto e : adjacency_list[v])
            if (e.target != v && e.target != bound) {
              if ((v < e.target) != direction) continue;
              if ((e.target < bound) != direction) continue;
              result =
                  min(result, e.value + f(e.target, direction, bound, k - 1));
              result = min(result, e.value + f(e.target, !direction, v, k - 1));
            }
        }
        return result;
      };
  auto result = infinity;
  for (auto v = 1; v <= n; v++) {
    result = min(result, f(v, true, n + 1, k - 1));
    result = min(result, f(v, false, 0, k - 1));
  }
  cout << (result == infinity ? -1 : result) << endl;
}
