#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define N (1<<18)
#define M 100000007
#define P complex<long long>
#define X real()
#define Y imag()
using namespace std;
int n, k, m, a[101010], b[101010], c[101010], noni[101010], ok[1010];
vector<int> ans, ni[101010];
vector<pair<int,int>> v;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k >> m;
for(int i=1; i<=m; i++) {
cin >> a[i] >> b[i] >> c[i];
if(c[i] == 0) {
for(int j=a[i]; j<=b[i]; j++)
noni[j] = 1;
} else {
for(int j=a[i]; j<=b[i]; j++)
ni[j].push_back(i);
v.push_back(make_pair(b[i], i));
}
}
sort(v.begin(), v.end());
for(int i=1; i<=n; i++) {
if(noni[i])
continue;
for(int j=1; j<=n; j++)
ok[j] = 0;
int nii = k;
int vn = -1;
bool bk = false;
for(auto u:v) {
if(vn >= a[u.second])
continue;
bool okk = false;
if(a[u.second] >= i)
vn = max(vn, i);
for(int j=u.first; j>=a[u.second]; j--) {
if(j == i)
continue;
if(!noni[j])
vn = j;
nii--; //
ok[j] = 1;
okk = true;
break;
}
}
if(!okk) {
bk = true;
ans.push_back(i);
continue;
}
}
if(bk)
continue;
for(int j=1; j<=n; j++) {
if(nii == 0)
break;
if(j == i || ok[j] || noni[j])
continue;
nii--;
}
if(nii)
ans.push_back(i);
}
if(ans.size() == 0)
cout << -1;
sort(ans.begin(), ans.end());
for(auto u:ans)
cout << u << "\n";
}