#include <bits/stdc++.h>
using namespace std;
long long costs[111][111];
long long dp[3][111][111][111];
long long Solve(int prev, int st, int en, int k) {
  if (k == 0) {
    return 0;
  }
  if (st > en) return 1000000000000000ll;
  if (st == en && k == 1) {
    return costs[prev][st];
  }
  int w = -1;
  if (prev == 0)
    w = 0;
  else if (prev == st - 1)
    w = 1;
  else if (prev == en + 1)
    w = 2;
  if (w == -1) exit(-1);
  if (dp[w][st][en][k] != -1) return dp[w][st][en][k];
  long long ans = 1000000000000000ll;
  for (int u = st; u <= en; u++) {
    if (costs[prev][u] != 1000000000000000ll) {
      ans = min(ans, costs[prev][u] + Solve(u, st, u - 1, k - 1));
      ans = min(ans, costs[prev][u] + Solve(u, u + 1, en, k - 1));
    }
  }
  return dp[w][st][en][k] = ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) costs[i][j] = 1000000000000000ll;
  for (int j = 1; j <= n; j++) costs[0][j] = 0;
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long costt;
    cin >> u >> v >> costt;
    costs[u][v] = min(costs[u][v], costt);
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 88; j++)
      for (int k = 0; k < 88; k++)
        for (int l = 0; l < 88; l++) dp[i][j][k][l] = -1;
  long long ans = Solve(0, 1, n, k);
  if (ans >= 1000000000000000ll / 2)
    printf("-1\n");
  else
    cout << ans << endl;
}
