#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3FFFFFFF;
const int N = 80;
int n, k, m;
int dp[2][N + 2][N + 2][N + 2];
vector<vector<int>> E[N + 2];
int sol(int d, int s, int l, int r) {
  if (!(1 <= s && s <= n)) return INF;
  if (d == 0 && s - l < 1 || d == 1 && s + l > n) return INF;
  if (r < 0 || r > k) return INF;
  if (r == 0) return 0;
  if (l < r) return INF;
  int &res = dp[d][s][l][r];
  if (res == -1) {
    res = INF;
    if (d == 0) {
      for (vector<int> &e : E[s]) {
        if (e[0] < s - l || e[0] >= s) continue;
        res = min(res, e[1] + sol(0, e[0], l - abs(s - e[0]), r - 1));
        res = min(res, e[1] + sol(1, e[0], abs(s - e[0]) - 1, r - 1));
      }
    } else {
      for (vector<int> &e : E[s]) {
        if (e[0] <= s || e[0] > s + l) continue;
        res = min(res, e[1] + sol(0, e[0], abs(s - e[0]) - 1, r - 1));
        res = min(res, e[1] + sol(1, e[0], l - abs(s - e[0]), r - 1));
      }
    }
  }
  return res;
}
int main() {
  for (int d = 0; d < 2; d++)
    for (int s = 0; s < N + 2; s++)
      for (int l = 0; l < N + 2; l++)
        for (int r = 0; r < N + 2; r++) dp[d][s][l][r] = -1;
  scanf("%d%d%d", &n, &k, &m);
  k--;
  for (int i = 0, u, v, c; i < m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    E[u].push_back({v, c});
  }
  int ans = INF;
  if (k == 0) {
    printf("0\n");
    return 0;
  }
  for (int s = 1; s <= n; s++) ans = min(ans, sol(0, s, s - 1, k));
  for (int s = 1; s <= n; s++) ans = min(ans, sol(1, s, n - s, k));
  printf("%d\n", ans >= INF ? -1 : ans);
}
