#include <bits/stdc++.h>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n, m;
struct hh {
  int u[2], v[2], vis[2];
  pair<int, int> nxt[2];
} q[202020];
map<pair<int, int>, pair<int, int> > lst;
int fa[202020], dep[202020];
int getfa(int x) { return x == fa[x] ? x : getfa(fa[x]); }
pair<int, int> st[202020];
int top;
void merge(int x, int y) {
  x = getfa(x), y = getfa(y);
  if (x == y) return;
  if (dep[x] > dep[y]) swap(x, y);
  fa[x] = y;
  pair<int, int> ret = make_pair(x, 0);
  if (dep[x] == dep[y]) ++dep[y], ret.second = 1;
  st[++top] = ret;
}
void reset(int pre) {
  pair<int, int> cur;
  while (top > pre)
    cur = st[top], --top, dep[fa[cur.first]] -= cur.second,
    fa[cur.first] = cur.first;
}
int ans;
vector<pair<int, int> > V[202020 << 2];
void add(int k, int l, int r, int x, int y, pair<int, int> e) {
  if (x > y) return;
  if (x <= l && r <= y) return V[k].push_back(e);
  int mid = (l + r) >> 1;
  if (x <= mid) add(k << 1, l, mid, x, y, e);
  if (y > mid) add(k << 1 | 1, mid + 1, r, x, y, e);
}
void solve(int k, int l, int r) {
  int pre = top;
  for (auto e : V[k]) merge(e.first, e.second);
  if (l != r) {
    int mid = (l + r) >> 1;
    solve(k << 1, l, mid);
    solve(k << 1 | 1, mid + 1, r);
    reset(pre);
    return;
  }
  if (q[l].vis[0] == -1)
    putchar('0' + (ans = (getfa(q[l].u[ans]) == getfa(q[l].v[ans]))));
  else {
    pair<int, int> nxt0 = q[l].nxt[ans];
    pair<int, int> nxt1 = q[l].nxt[ans ^ 1];
    if (!q[l].vis[ans])
      add(1, 1, m, l + 1, nxt0.first - 1, make_pair(q[l].u[ans], q[l].v[ans])),
          q[nxt0.first].vis[nxt0.second] = 1;
    if (q[l].vis[ans ^ 1])
      add(1, 1, m, l + 1, nxt1.first - 1,
          make_pair(q[l].u[ans ^ 1], q[l].v[ans ^ 1])),
          q[nxt1.first].vis[nxt1.second] = 1;
  }
  reset(pre);
}
int main() {
  file();
  read(n, m);
  int z, x, y;
  if (n == 2) {
    int cur = 0;
    while (m--) read(z, x, y), z == 1 ? cur ^= 1 : putchar('0' + cur);
    return 0;
  }
  for (int i = (1); i <= (m); i++) {
    read(z, x, y);
    int xx, yy;
    if (z == 2) {
      for (int k = (0); k <= (1); k++)
        xx = (x - 1 + k) % n + 1, yy = (y - 1 + k) % n + 1, q[i].u[k] = xx,
        q[i].v[k] = yy;
      q[i].vis[0] = -1;
    } else
      for (int k = (0); k <= (1); k++)
        xx = (x - 1 + k) % n + 1, yy = (y - 1 + k) % n + 1,
        xx > yy ? swap(xx, yy) : void(), q[i].u[k] = xx, q[i].v[k] = yy;
  }
  for (int i = (1); i <= (m); i++) {
    if (q[i].vis[0] == -1) continue;
    for (int k = (0); k <= (1); k++) {
      int u = q[i].u[k], v = q[i].v[k];
      pair<int, int> cur = lst[make_pair(u, v)];
      if (cur.first) q[cur.first].nxt[cur.second] = make_pair(i, k);
      lst[make_pair(u, v)] = make_pair(i, k);
    }
  }
  for (int i = (1); i <= (n); i++) fa[i] = i;
  for (int i = (1); i <= (m); i++)
    for (int k = (0); k <= (1); k++)
      if (!q[i].nxt[k].first) q[i].nxt[k].first = m + 1;
  solve(1, 1, m);
  return 0;
}
