#include <bits/stdc++.h>
using namespace std;
int n, k, m, a[100][100], dp[100][100][100];
int calc(int l, int cur, int dem) {
  if (dem > k) dp[l][cur][dem] = 0;
  if (dp[l][cur][dem] != 1000000007) return dp[l][cur][dem];
  int res = 1000000007 + 1;
  if (l <= cur) {
    for (int i = l; i < cur; i++)
      if (a[cur][i] != 1000000007)
        res = min(res, a[cur][i] +
                           min(calc(l, i, dem + 1), calc(cur - 1, i, dem + 1)));
  } else {
    for (int i = cur + 1; i <= l; i++)
      if (a[cur][i] != 1000000007)
        res = min(res, a[cur][i] +
                           min(calc(cur + 1, i, dem + 1), calc(l, i, dem + 1)));
  }
  dp[l][cur][dem] = res;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = 1000000007;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int h = 0; h <= k + 1; h++) dp[i][j][h] = 1000000007;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    a[u][v] = min(a[u][v], w);
  }
  int res = calc(n, 0, 1);
  if (res >= 1000000007)
    cout << -1;
  else
    cout << res;
}
