#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' && c != '-') c = getchar();
  if (c == '-') f = 1, c = getchar();
  while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f ? -x : x;
}
const int SIZE = 2e5 + 100;
int n, m, lst;
int a[SIZE];
int id_cnt;
map<pair<int, int>, int> M;
inline int ID(int x, int y) {
  pair<int, int> p = make_pair(x, y);
  if (M.count(p) == 0) M[p] = ++id_cnt;
  return M[p];
}
int ins[SIZE], x[SIZE], y[SIZE];
bool mark[SIZE << 1];
int suf[SIZE << 1];
int nxt[SIZE][2];
vector<pair<int, int> > G[SIZE << 2];
pair<int, int> PP;
void Push(int L, int R, int p, int l, int r) {
  if (L == l && R == r) {
    G[p].push_back(PP);
    return;
  }
  int mid = (L + R) >> 1;
  if (r <= mid)
    Push(L, mid, (p << 1), l, r);
  else if (l > mid)
    Push(mid + 1, R, (p << 1 | 1), l, r);
  else
    Push(L, mid, (p << 1), l, mid), Push(mid + 1, R, (p << 1 | 1), mid + 1, r);
}
int fa[SIZE], sz[SIZE];
int Find(int x) {
  while (x ^ fa[x]) x = fa[x];
  return x;
}
int QAQ[SIZE], TP;
void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  if (x == y) return;
  if (sz[x] > sz[y]) swap(x, y);
  sz[y] += sz[x];
  fa[x] = y;
  QAQ[++TP] = x;
}
void Solve(int L, int R, int p) {
  int tmp = TP;
  for (pair<int, int> E : G[p]) {
    Merge(E.first, E.second);
  }
  int mid = (L + R) >> 1;
  if (L == R) {
    if (ins[L] == 1) {
      int tx = (x[L] + lst - 1) % n + 1, ty = (y[L] + lst - 1) % n + 1, id;
      if (tx > ty) swap(tx, ty);
      mark[ID(tx, ty)] ^= 1;
      tx = x[L], ty = y[L];
      if (tx > ty) swap(tx, ty);
      id = ID(tx, ty);
      if (mark[id]) {
        PP = make_pair(tx, ty);
        if (L + 1 <= nxt[L][0]) Push(1, m, 1, L + 1, nxt[L][0]);
      }
      tx = x[L] % n + 1, ty = y[L] % n + 1;
      if (tx > ty) swap(tx, ty);
      id = ID(tx, ty);
      if (mark[id]) {
        PP = make_pair(tx, ty);
        if (L + 1 <= nxt[L][1]) Push(1, m, 1, L + 1, nxt[L][1]);
      }
    } else {
      x[L] = (x[L] + lst - 1) % n + 1, y[L] = (y[L] + lst - 1) % n + 1;
      if (Find(x[L]) == Find(y[L]))
        lst = 1;
      else
        lst = 0;
      printf("%d", lst);
    }
  } else {
    int mid = (L + R) >> 1;
    Solve(L, mid, (p << 1)), Solve(mid + 1, R, (p << 1 | 1));
  }
  while (TP > tmp) {
    int u = QAQ[TP];
    sz[fa[u]] -= sz[u];
    fa[u] = u;
    --TP;
  }
}
void _main() {
  n = rd(), m = rd();
  for (register int i = 1, _n = m; i <= _n; ++i) {
    ins[i] = rd();
    x[i] = rd(), y[i] = rd();
  }
  for (register int i = 1, _n = n; i <= _n; ++i) fa[i] = i, sz[i] = 1;
  for (register int i = 1, _n = 2 * m; i <= _n; ++i) suf[i] = m;
  for (register int i = m, _n = 1; i >= _n; --i)
    if (ins[i] == 1) {
      int tx = x[i], ty = y[i], id;
      if (tx > ty) swap(tx, ty);
      id = ID(tx, ty);
      nxt[i][0] = suf[id];
      suf[id] = i - 1;
      tx = x[i] % n + 1, ty = y[i] % n + 1;
      if (tx > ty) swap(tx, ty);
      id = ID(tx, ty);
      nxt[i][1] = suf[id];
      suf[id] = i - 1;
    }
  Solve(1, m, 1);
}
int main() {
  _main();
  return 0;
}
