#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y, z;
vector<vector<pair<int, int> > > v;
vector<vector<vector<int> > > dp;
int solve(int u, int a, int c) {
  if (c == k) return 0;
  if (a == u) return MOD;
  if (dp[u][a][c] != -1) return dp[u][a][c];
  int ans = MOD;
  for (auto& it : v[u]) {
    if (a > u && it.first <= a && it.first > u) {
      ans = min(ans, it.second + solve(it.first, a, c + 1));
      ans = min(ans, it.second + solve(it.first, u + 1, c + 1));
    } else if (a < u && it.first >= a && it.first < u) {
      ans = min(ans, it.second + solve(it.first, u - 1, c + 1));
      ans = min(ans, it.second + solve(it.first, a, c + 1));
    }
  }
  return dp[u][a][c] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> m;
  v.assign(n, vector<pair<int, int> >(0));
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    --x, --y;
    v[x].push_back(make_pair(y, z));
  }
  dp.assign(n, vector<vector<int> >(n, vector<int>(k, -1)));
  int ans = MOD;
  for (int i = 0; i < n; i++) {
    ans = min(ans, solve(i, n - 1, 1));
    ans = min(ans, solve(i, 0, 1));
  }
  if (ans == MOD) ans = -1;
  cout << ans << "\n";
  return 0;
}
