#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 83;
const int MAXM = 4007;
struct eT {
  void setd(int _u, int _v, int _w, int _l) {
    u = _u, v = _v, w = _w, last = _l;
  }
  int u, v, w, last;
} edge[MAXM];
int n, tk;
int m;
int ke, la[MAXN];
int dp[2][MAXN][MAXN][2];
void init();
void input();
void work();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d", &n, &tk);
  scanf("%d", &m);
  int u, v, w;
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    edge[ke].setd(u, v, w, la[u]);
    la[u] = ke++;
  }
}
void work() {
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  for (int i = 0; i <= n + 1; ++i)
    for (int j = i; j <= n + 1; ++j) dp[1][i][j][0] = dp[1][i][j][1] = 0;
  int t, now, v;
  for (int nk = 2; nk <= tk; ++nk) {
    t = nk & 1;
    memset(dp[t], 0x3f3f3f3f, sizeof(dp[t]));
    for (int l = 0; l <= n + 1; ++l) {
      for (int r = l + 1; r <= n + 1; ++r) {
        for (int d = 0; d < 2; ++d) {
          now = d ? r : l;
          for (int i = la[now]; ~i; i = edge[i].last) {
            v = edge[i].v;
            if (v > l && v < r) {
              dp[t][l][r][d] =
                  min(dp[t][l][r][d],
                      edge[i].w + (((dp[t ^ 1][l][v][1]) < (dp[t ^ 1][v][r][0]))
                                       ? (dp[t ^ 1][l][v][1])
                                       : (dp[t ^ 1][v][r][0])));
            }
          }
        }
      }
    }
  }
  int ans = INF;
  t = tk & 1;
  for (int l = 0; l <= n + 1; ++l)
    for (int r = l + 1; r <= n + 1; ++r)
      for (int d = 0; d < 2; ++d)
        ans = (((ans) < (dp[t][l][r][d])) ? (ans) : (dp[t][l][r][d]));
  printf("%d\n", (ans < 1e9) ? ans : -1);
}
