#include <bits/stdc++.h>
using namespace std;
int INF = 1000 * 1000 * 1000;
vector<vector<pair<int, int>>> adj;
int mem[80][80][80][80];
int dp(int cur, int closestLeft, int closestRight, int remainingMoves) {
  if (remainingMoves == 0) return 0;
  if (mem[cur][closestLeft][closestRight][remainingMoves] != -1) {
    return mem[cur][closestLeft][closestRight][remainingMoves];
  }
  int res = INF;
  for (auto& nxt : adj[cur])
    if (nxt.first != cur) {
      if (nxt.first >= closestLeft && nxt.first <= closestRight) {
        int newClosestLeft = closestLeft;
        if (nxt.first > cur) newClosestLeft = cur + 1;
        int newClosestRight = closestRight;
        if (nxt.first < cur) newClosestRight = cur - 1;
        res = min(res, nxt.second + dp(nxt.first, newClosestLeft,
                                       newClosestRight, remainingMoves - 1));
      }
    }
  return mem[cur][closestLeft][closestRight][remainingMoves] = res;
}
int main() {
  int n, k, m;
  cin >> n >> k >> m;
  memset(mem, -1, sizeof(mem));
  adj.resize(n);
  for (int i = 0; i < m; i++) {
    int u;
    cin >> u;
    u--;
    int v;
    cin >> v;
    v--;
    int c;
    cin >> c;
    adj[u].push_back(make_pair(v, c));
  }
  int res = INF;
  for (int start = 0; start < n; start++) {
    int temp = dp(start, 0, n - 1, k - 1);
    res = min(res, temp);
  }
  if (res >= INF)
    cout << -1 << endl;
  else
    cout << res << endl;
}
