#include <stdio.h>

int main()
{
  char *p, buf[32];
  int i, n, q, c, x, y;
  fgets(buf, 32, stdin);
  for (n=0,p=buf; *p!=' '; n = n * 10 + *(p++) - '0'); 
  int s[n];
  for (i=0; i<n; i++) s[i]=i;
  for (q=0,p++; *p!='\n'; q = q * 10 + *(p++) - '0');
  for (i=0; i<q; i++) {
    fgets(buf, 32, stdin);
    c = buf[0];
    for (x=0,p=buf+2; *p!=' '; x = x * 10 + *(p++) - '0');
    for (y=0,p++; *p!='\n'; y = y * 10 + *(p++) - '0');
    if (c=='0') {
      while(s[x]!=x) x=s[x];
      while(s[y]!=y) y=s[y];
      if (s[x]<s[y]) s[y] = s[x];
      else s[x] = s[y];
    } else {
      while(s[x]!=x) x=s[x];
      while(s[y]!=y) y=s[y];
      putc_unlocked('0'+(x==y), stdout);
      putc_unlocked('\n', stdout);
    }
  }
  return 0;
}

