#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
int n, K, m;
int g[100][100];
struct edge {
  int to, cost;
};
vector<edge> G[100];
int memo[80][80][80][90];
bool done[80][80][80][90];
int ans(int i, int j, int k, int l) {
  if (done[i][j][k][l]) {
    return memo[i][j][k][l];
  }
  if (l == 0) {
    done[i][j][k][l] = true;
    return memo[i][j][k][l] = 0;
  }
  if (i >= j) {
    done[i][j][k][l] = true;
    return memo[i][j][k][l] = 2000000000;
  }
  int ret = 2000000000;
  int s = k;
  for (auto v : G[s]) {
    if (i <= v.to && v.to <= j) {
      int st = i, ed = j;
      if (v.to < s) {
        ed = s - 1;
      } else {
        st = s + 1;
      }
      ret = min(ret, ans(st, ed, v.to, l - 1) + v.cost);
    }
  }
  done[i][j][k][l] = true;
  return memo[i][j][k][l] = ret;
}
int main() {
  cin >> n >> K >> m;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      g[i][j] = 2000000000;
    }
  }
  for (int i = 0; i < (m); i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    g[u][v] = min(g[u][v], c);
  }
  if (K == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      if (i == j) continue;
      if (g[i][j] < 2000000000) G[i].push_back((edge){j, g[i][j]});
    }
  }
  int answer = 2000000000;
  for (int i = 0; i < (n); i++) {
    answer = min(answer, ans(0, n - 1, i, K - 1));
  }
  if (answer == 2000000000) {
    cout << -1 << endl;
  } else {
    cout << answer << endl;
  }
  return 0;
}
