#include <bits/stdc++.h>
int x, y, z, n, m, k, i, j, kk, l, ans[88][88][88][2], dist[88][88];
int main() {
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (dist[x][y] == 0 || dist[x][y] > z) {
      dist[x][y] = z;
    }
  }
  for (kk = 1; kk <= k; kk++) {
    for (i = 1; i <= n; i++) {
      for (j = i; j <= n; j++) {
        ans[i][j][kk][0] = 1000000000;
        ans[i][j][kk][1] = 1000000000;
        for (l = i; l <= j; l++) {
          if ((i == 1 || dist[i - 1][l]) && (l < j || kk == 1) &&
              ans[l + 1][j][kk - 1][0] != 1000000000)
            ans[i][j][kk][0] =
                (ans[i][j][kk][0] < dist[i - 1][l] + ans[l + 1][j][kk - 1][0]
                     ? ans[i][j][kk][0]
                     : dist[i - 1][l] + ans[l + 1][j][kk - 1][0]);
          if ((i == 1 || dist[i - 1][l]) && (l > i || kk == 1) &&
              ans[i][l - 1][kk - 1][1] != 1000000000)
            ans[i][j][kk][0] =
                (ans[i][j][kk][0] < dist[i - 1][l] + ans[i][l - 1][kk - 1][1]
                     ? ans[i][j][kk][0]
                     : dist[i - 1][l] + ans[i][l - 1][kk - 1][1]);
          if ((j == n || dist[j + 1][l]) && (l < j || kk == 1) &&
              ans[l + 1][j][kk - 1][0] != 1000000000)
            ans[i][j][kk][1] =
                (ans[i][j][kk][1] < dist[j + 1][l] + ans[l + 1][j][kk - 1][0]
                     ? ans[i][j][kk][1]
                     : dist[j + 1][l] + ans[l + 1][j][kk - 1][0]);
          if ((j == n || dist[j + 1][l]) && (l > i || kk == 1) &&
              ans[i][l - 1][kk - 1][1] != 1000000000)
            ans[i][j][kk][1] =
                (ans[i][j][kk][1] < dist[j + 1][l] + ans[i][l - 1][kk - 1][1]
                     ? ans[i][j][kk][1]
                     : dist[j + 1][l] + ans[i][l - 1][kk - 1][1]);
        }
      }
    }
  }
  if (ans[1][n][k][0] == 1000000000 && ans[1][n][k][1] == 1000000000)
    printf("-1");
  else
    printf("%d\n", (ans[1][n][k][0] < ans[1][n][k][1] ? ans[1][n][k][0]
                                                      : ans[1][n][k][1]));
}
