#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 81;
int N, K;
struct Edge {
  int to, cost;
  Edge(int to, int cost) {
    this->to = to;
    this->cost = cost;
  }
};
vector<Edge> edges[MAX_N];
int M[MAX_N][MAX_N][MAX_N][MAX_N];
int solve(int a, int b, int c, int k) {
  int &sol = M[a][b][c][k];
  if (sol != -1) {
    return sol;
  }
  if (k == 0) {
    return 0;
  }
  int best = -2;
  for (int j = 0; j < edges[c].size(); ++j) {
    int i = edges[c][j].to;
    if ((i <= a) || (i >= b)) {
      continue;
    }
    int cost = edges[c][j].cost;
    int sub = -2;
    if (i < c) {
      sub = solve(a, c, i, k - 1);
    } else {
      sub = solve(c, b, i, k - 1);
    }
    if (sub >= 0) {
      sub += cost;
      if ((best == -2) || (sub < best)) {
        best = sub;
      }
    }
  }
  return sol = best;
}
int main() {
  int m;
  scanf("%d%d%d", &N, &K, &m);
  memset(M, -1, sizeof(M));
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    edges[u].push_back(Edge(v, c));
  }
  int best = -2;
  for (int i = 1; i <= N; ++i) {
    int opt = solve(0, N + 1, i, K - 1);
    if (opt == -2) {
      continue;
    }
    if ((best == -2) || (opt < best)) {
      best = opt;
    }
  }
  if (best == -2) {
    best = -1;
  }
  printf("%d\n", best);
  return 0;
}
