#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans, tot;
unordered_map<long long, int> id;
int op[400010], d[400010], fa[400010], rk[400010], lg[400010], hs[400010];
struct node {
  int u, v;
  long long h;
  void bb() {
    if (u > v) swap(u, v);
    h = (long long)u << 30 | v;
  }
} e[400010], g[400010];
int getfa(int x) { return fa[x] == x ? x : getfa(fa[x]); }
void uni(int x, int y, int z) {
  x = getfa(x), y = getfa(y);
  if (rk[x] <= rk[y]) {
    fa[x] = y;
    lg[++tot] = x;
    hs[tot] = z;
    if (rk[x] == rk[y]) rk[y]++;
  } else {
    fa[y] = x;
    lg[++tot] = y;
    hs[tot] = z;
  }
}
void del(int x) {
  int i;
  for (i = tot; hs[i] != x; i--) {
    fa[lg[i]] = lg[i];
  }
  fa[lg[i]] = lg[i];
  int u = tot;
  tot = i - 1;
  for (i++; i <= u; i++) uni(g[hs[i]].u, g[hs[i]].v, hs[i]);
}
void solve(int be, int en) {
  for (int i = 1; i <= n; i++) fa[i] = i, rk[i] = 0;
  tot = 0;
  vector<int> v(cnt + 3), vv(cnt + 3);
  for (int i = 1; i < be; i++)
    if (op[i] == 1) v[d[i]] ^= 1;
  for (int i = be; i <= en; i++)
    if (op[i] == 1) vv[d[i]] = vv[d[i + m]] = 1;
  for (int i = 1; i <= cnt; i++)
    if (v[i] && !vv[i]) uni(g[i].u, g[i].v, i);
  for (int i = 1; i <= cnt; i++)
    if (v[i] && vv[i]) uni(g[i].u, g[i].v, i);
  for (int i = be; i <= en; i++) {
    if (ans) e[i] = e[i + m], d[i] = d[i + m];
    if (op[i] == 1) {
      v[d[i]] ^= 1;
      if (v[d[i]])
        uni(e[i].u, e[i].v, d[i]);
      else
        del(d[i]);
    } else {
      int x = getfa(e[i].u), y = getfa(e[i].v);
      if (x != y)
        putchar('0'), ans = 0;
      else
        putchar('1'), ans = 1;
    }
  }
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &op[i]);
    scanf("%d%d", &e[i].u, &e[i].v);
    e[i].bb();
    op[i + m] = op[i];
    e[i + m] = {e[i].u % n + 1, e[i].v % n + 1};
    e[i + m].bb();
  }
  for (int i = 1, tot = m * 2; i <= tot; i++) {
    long long t = e[i].h;
    if (!id[t]) id[t] = ++cnt, g[cnt] = e[i];
    d[i] = id[t];
  }
  int B = sqrt(m) * 6;
  B = min(B, m);
  for (int i = 1; i <= m; i += B) solve(i, min(i + B - 1, m));
  return 0;
}
