#include <bits/stdc++.h>
using namespace std;
namespace trcyx {
int pa[65536 * 4], size[65536 * 4];
vector<int> vx, vp, vs;
void init() {
  for (int i = 0; i < 65536 * 4; i++) pa[i] = i, size[i] = 1;
}
int find(int x) {
  if (pa[x] == x) return x;
  return find(pa[x]);
}
void save(int x) {
  vx.push_back(x);
  vp.push_back(pa[x]);
  vs.push_back(size[x]);
}
void merge(int x, int y) {
  x = find(x), y = find(y);
  save(x);
  save(y);
  if (x == y) return;
  if (size[x] > size[y]) swap(x, y);
  pa[x] = y, size[y] += size[x];
}
int together(int x, int y) { return find(x) == find(y); }
void pop(int y) {
  while (y--) {
    int x = vx[vx.size() - 1];
    pa[x] = vp[vp.size() - 1];
    size[x] = vs[vs.size() - 1];
    vx.pop_back();
    vp.pop_back();
    vs.pop_back();
  }
}
};  // namespace trcyx
int n, m;
int ti[65536 * 4], xi[65536 * 4], yi[65536 * 4];
int get(int x) { return (x + 1) % n; }
pair<int, int> make(int x, int y) { return make_pair(min(x, y), max(x, y)); }
map<pair<int, int>, int> lst, exist;
vector<pair<int, int> > tree[65536 * 4 * 2];
void upd(int a, int b, int l, int r, int id, pair<int, int> p) {
  if (l >= a and r <= b) {
    tree[id].push_back(p);
    return;
  }
  int mid = (l + r) / 2;
  if (a <= mid) upd(a, b, l, mid, id << 1, p);
  if (b > mid) upd(a, b, mid + 1, r, id << 1 | 1, p);
}
void link(int i, int x, int y) {
  if (lst[make(x, y)]) upd(lst[make(x, y)] + 1, i, 1, 65536 * 4, 1, make(x, y));
  lst[make(x, y)] = i;
}
int op[65536 * 4 * 2];
void ins(int x) {
  for (int i = 0; i < tree[x].size(); i++)
    if (exist[tree[x][i]]) {
      trcyx::merge(tree[x][i].first, tree[x][i].second);
      op[x]++;
      op[x]++;
    }
}
void era(int x) { trcyx::pop(op[x]); }
vector<int> res, now;
void ask(int x, int l, int r, int id) {
  now.push_back(id);
  if (l == r) return;
  int mid = (l + r) / 2;
  if (x <= mid)
    ask(x, l, mid, id << 1);
  else
    ask(x, mid + 1, r, id << 1 | 1);
}
void ask(int x) {
  now.clear();
  ask(x, 1, 65536 * 4, 1);
  int j = 0;
  while (j < res.size() and j < now.size() and res[j] == now[j]) j++;
  while (res.size() > j) era(res[res.size() - 1]), res.pop_back();
  for (int i = j; i < now.size(); i++) res.push_back(now[i]), ins(now[i]);
}
int Flg = 0;
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &ti[i], &xi[i], &yi[i]);
    xi[i]--, yi[i]--;
    link(i, xi[i], yi[i]);
    link(i, get(xi[i]), get(yi[i]));
  }
  for (map<pair<int, int>, int>::iterator it = lst.begin(); it != lst.end();
       it++)
    upd((it->second) + 1, m, 1, 65536 * 4, 1, it->first);
  trcyx::init();
  for (int i = 1; i <= m; i++) {
    if (Flg) xi[i] = get(xi[i]), yi[i] = get(yi[i]);
    if (ti[i] == 1) {
      exist[make(xi[i], yi[i])] ^= 1;
    } else {
      ask(i);
      Flg = trcyx::together(xi[i], yi[i]);
      putchar('0' + Flg);
    }
  }
  return 0;
}
