#include<stdio.h>
#include<stdlib.h>

typedef struct group {
    int n[10000];
} Group;

int main(){
    int i, j;
    int n, q;
    int com, x, y;
    int count=0;
    int ans=0;
    scanf("%d%d", &n, &q);

    Group *group;
    group = calloc(q, sizeof(Group));

    for(i=0;i<q;i++){
        scanf("%d%d%d", &com, &x, &y);
        if(com==0){
            ans=0;
            for(j=0;j<count;j++){
                if(group[j].n[x] || group[j].n[y]){
                    group[j].n[x] = group[j].n[y] = 1;
                    ans=1;
                    break;
                }
            }
            if(ans==0){
                group[count].n[x] = group[count].n[y] = 1;
                count++;
            }
        }else{
            ans=0;
            for(j=0;j<count;j++){
                if(group[j].n[x] && group[j].n[y]){
                    ans=1;
                    break;
                }
            }
            //printf("------------------------------");
            printf("%d\n", ans);
        }

        for(j=0;j<count;j++){
            for(int k=j+1;k<count;k++){
                for(int l=0;l<n;l++){
                    if(group[j].n[l] && group[k].n[l]){
                        for(int m=0;m<n;m++){
                            group[j].n[m] |= group[k].n[m];
                            group[k].n[m] = 0;
                        }
                        break;
                    }
                }
            }
        }
/*
        for(j=0;j<count;j++){
            printf("group = ");
            for(int k=0;k<n;k++)printf("%d", group[j].n[k]);
            printf("\n");
        }
        */
    }
    return 0;
}
