#include <bits/stdc++.h>
using namespace std;
const int maxN = 88;
int d[maxN][maxN][maxN];
int r[maxN][maxN];
int main(void) {
  ios_base::sync_with_stdio(0);
  int n, kk, m;
  cin >> n >> kk >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      r[i][j] = (int)1e9;
    }
  }
  for (int i = 1; i <= m; i++) {
    int c, x, y;
    cin >> x >> y >> c;
    if (x == y) {
      continue;
    }
    x--;
    y--;
    r[x][y] = min(r[x][y], c);
  }
  int ans = (int)1e9;
  for (int len = 1; len <= n; len++) {
    for (int i = 0; i < n; i++) {
      for (int fw = 0; fw < 2; fw++) {
        int j = i + (fw ? len : -len) - (fw ? 1 : -1);
        if (j >= 0 && j <= n - 1) {
          for (int k = 1; k <= n; k++) {
            d[i][j][k] = (int)1e9;
            if (k == 1) {
              d[i][j][k] = 0;
              if (k == kk) {
                ans = min(ans, d[i][j][kk]);
              }
              continue;
            }
            if (i < j) {
              for (int p = i; p <= j; p++) {
                if (r[i][p] < 1e8) {
                  d[i][j][k] =
                      min(d[i][j][k],
                          min(d[p][j][k - 1], d[p][i + 1][k - 1]) + r[i][p]);
                }
              }
            } else {
              for (int p = j; p <= i; p++) {
                if (r[i][p] < 1e8) {
                  d[i][j][k] =
                      min(d[i][j][k],
                          min(d[p][i - 1][k - 1], d[p][j][k - 1]) + r[i][p]);
                }
              }
            }
            if (k == kk) {
              ans = min(ans, d[i][j][kk]);
            }
          }
        }
      }
    }
  }
  if (ans > 1e8) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}
