#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;
const int LOG = 20;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
bool mark[2 * maxN];
int n, par[maxN], sz[maxN];
int q, type[maxN], lvl = 0;
int N = 0, last = 0;
pair<int, int> E[maxN], iQ[2 * maxN];
stack<int> st[LOG];
map<pair<int, int>, int> MAPPA, mp;
vector<int> Q[2 * maxN], seg[4 * maxN];
int nxt(int x) { return x % n + 1; }
int getpar(int v) { return (par[v] == v ? v : getpar(par[v])); }
void join(int u, int v) {
  u = getpar(u);
  v = getpar(v);
  if (u == v) {
    st[lvl].push(-1);
    return;
  }
  if (sz[u] > sz[v]) swap(u, v);
  st[lvl].push(u);
  par[u] = v;
  sz[v] += sz[u];
  return;
}
void undo() {
  int u = st[lvl].top();
  st[lvl].pop();
  if (u == -1) return;
  int v = par[u];
  par[u] = u;
  sz[v] -= sz[u];
  return;
}
void put(int l, int r, int ix, int id = 1, int s = 0, int e = q) {
  if (l <= s && e <= r) {
    seg[id].push_back(ix);
    return;
  }
  if (l >= e || s >= r) return;
  int md = (s + e) >> 1;
  put(l, r, ix, (id << 1), s, md);
  put(l, r, ix, ((id << 1) ^ 1), md, e);
  return;
}
void MIKASA(int id = 1, int s = 0, int e = q) {
  for (int ix : seg[id]) {
    pair<int, int> pp = iQ[ix];
    join(pp.first, pp.second);
  }
  if (e - s <= 1) {
    int u, v;
    tie(u, v) = E[s];
    int x = nxt(u), y = nxt(v);
    if (x > y) swap(x, y);
    if (last) {
      swap(u, x);
      swap(v, y);
    }
    if (type[s] == 2) {
      last = (getpar(u) == getpar(v));
      printf("%d", last);
    } else {
      int i = MAPPA[{u, v}];
      mark[i] ^= 1;
      if (mark[i]) put(s + 1, *upper_bound(Q[i].begin(), Q[i].end(), s), i);
      i = MAPPA[{x, y}];
      if (mark[i]) put(s + 1, *upper_bound(Q[i].begin(), Q[i].end(), s), i);
    }
  } else {
    int md = (s + e) >> 1;
    lvl++;
    MIKASA((id << 1), s, md);
    lvl++;
    MIKASA(((id << 1) ^ 1), md, e);
  }
  while (!st[lvl].empty()) undo();
  lvl--;
  return;
}
int main() {
  time_t START = clock();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < q; i++) {
    int u, v;
    scanf("%d%d%d", type + i, &u, &v);
    int x = nxt(u), y = nxt(v);
    if (u > v) swap(u, v);
    if (x > y) swap(x, y);
    E[i] = {u, v};
    if (!MAPPA.count({u, v})) {
      MAPPA[{u, v}] = ++N;
      iQ[N] = {u, v};
    }
    if (!MAPPA.count({x, y})) {
      MAPPA[{x, y}] = ++N;
      iQ[N] = {x, y};
    }
    if (type[i] == 1) {
      Q[MAPPA[{u, v}]].push_back(i);
      Q[MAPPA[{x, y}]].push_back(i);
    }
  }
  for (int i = 1; i <= N; i++) Q[i].push_back(q);
  MIKASA();
  printf("\n");
  time_t FINISH = clock();
  cerr << "Execution time: "
       << (long double)(FINISH - START) / CLOCKS_PER_SEC * 1000.0
       << " milliseconds.\n";
  return 0;
}
