#include <bits/stdc++.h>
using namespace std;
int dp[81][81][81], n, m, i, j, k, ans, inf = 1000007, x, y, l, len;
pair<int, int> p;
vector<pair<int, int> > g[82];
int main() {
  cin >> n >> m;
  if (m > n) {
    cout << -1 << endl;
    return 0;
  }
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> x >> y >> l;
    if (x == y) continue;
    p.first = y;
    p.second = l;
    g[x].push_back(p);
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) dp[i][j][k] = inf;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) dp[i][j][1] = 0;
  for (k = 2; k <= m; k++)
    for (j = 1; j < n; j++)
      for (i = 1; i <= n - j; i++) {
        len = g[i].size();
        for (l = 0; l < len; l++) {
          if (g[i][l].first < i) continue;
          if (g[i][l].first > i + j) continue;
          dp[i][i + j][k] =
              min(dp[i][i + j][k], min(dp[g[i][l].first][i + 1][k - 1],
                                       dp[g[i][l].first][i + j][k - 1]) +
                                       g[i][l].second);
        }
        len = g[i + j].size();
        for (l = 0; l < len; l++) {
          if (g[i + j][l].first > i + j) continue;
          if (g[i + j][l].first < i) continue;
          dp[i + j][i][k] =
              min(dp[i + j][i][k], min(dp[g[i + j][l].first][i + j - 1][k - 1],
                                       dp[g[i + j][l].first][i][k - 1]) +
                                       g[i + j][l].second);
        }
      }
  ans = inf;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) ans = min(ans, dp[i][j][m]);
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
