#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, r;
} pts[110];
vector<int> g[110];
int COL;
int co[110], vis[110], bel[110];
int cnt1[110], cnt2[110];
void dfs(int x, int col = 0, int cc = ++COL) {
  vis[x] = 1;
  co[x] = col;
  bel[x] = cc;
  for (int i = 0; i < g[x].size(); i++)
    if (!vis[g[x][i]]) dfs(g[x][i], col ^ 1, cc);
}
const int maxn = 100 * 1000 + 10;
int dp[maxn], tmp1[maxn], tmp2[maxn];
vector<int> c1[110], c2[110];
int main() {
  int n, k, t;
  scanf("%d%d%d", &n, &k, &t);
  for (int i = 0; i < k; i++) scanf("%d%d%d", &pts[i].x, &pts[i].y, &pts[i].r);
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++)
      if (i != j) {
        if (pts[i].x == pts[j].x || pts[i].y == pts[j].y) {
          g[i].push_back(j);
          g[j].push_back(i);
        }
      }
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < k; i++)
    if (!vis[i]) dfs(i);
  for (int i = 0; i < k; i++)
    if (!co[i])
      c1[bel[i]].push_back(i);
    else
      c2[bel[i]].push_back(i);
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 1; i <= COL; i++) {
    memcpy(tmp1, dp, sizeof(tmp1));
    memcpy(tmp2, dp, sizeof(tmp2));
    for (int j = 0; j < c1[i].size(); j++) {
      int x = c1[i][j];
      for (int mx = maxn - 1; mx >= pts[x].r; mx--) {
        tmp2[mx] += tmp2[mx - pts[x].r];
        if (tmp2[mx] > 0x3f3f3f3f) tmp2[mx] = 0x3f3f3f3f;
      }
    }
    for (int j = 0; j < c2[i].size(); j++) {
      int x = c2[i][j];
      for (int mx = maxn - 1; mx >= pts[x].r; mx--) {
        tmp1[mx] += tmp1[mx - pts[x].r];
        if (tmp1[mx] > 0x3f3f3f3f) tmp1[mx] = 0x3f3f3f3f;
      }
    }
    for (int mx = 0; mx < maxn; mx++) {
      dp[mx] += tmp1[mx] + tmp2[mx] - dp[mx] - dp[mx];
      if (dp[mx] > 0x3f3f3f3f) dp[mx] = 0x3f3f3f3f;
    }
  }
  int cur = 0;
  for (int i = 0; i < maxn; i++) {
    cur += dp[i];
    if (cur >= t) {
      printf("%d\n", i);
      return 0;
    }
  }
}
