#include #include #include #include #include #include #include #include #define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i]; typedef long long int ll; using namespace std; const int MOD = 1000000007; int cnt[6]; vector a1[100010],b1[100010]; int main(){ int n,m; cin >>n>>m; int ans=1e9; vector x(n),a(n),b(n); for(int i=0;i>x[i] >> a[i] >> b[i]; a1[a[i]].push_back(i); b1[b[i]].push_back(i); } for(int i=0;i