#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const int N = 200500;
const int bl = 6000;
vector<int> g[N];
map<pair<int, int>, bool> ok, bad;
int n, q, last, timer, p[N], h[N], u[N], x[N], y[N], tp[N];
int get(int v) { return p[v] = (v == p[v] ? v : get(p[v])); }
inline void unite(int x, int y) {
  x = get(x), y = get(y);
  if (h[x] > h[y]) swap(x, y);
  p[x] = y;
  h[y] += (h[x] == h[y]);
}
void dfs(int v) {
  u[v] = timer;
  for (auto to : g[v]) {
    if (u[to] != timer) dfs(to);
  }
}
inline pair<int, int> f(int x, int y) {
  if (x > y) return {y, x};
  return {x, y};
}
inline void erase_edge(int v1, int v2) {
  for (int i = 0; i < (int)g[v1].size(); i++) {
    if (g[v1][i] == v2) {
      swap(g[v1][i], g[v1][(int)g[v1].size() - 1]);
      g[v1].pop_back();
      break;
    }
  }
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= q; i++) scanf("%d %d %d", &tp[i], &x[i], &y[i]);
  for (int i = 1; i <= q; i += bl) {
    bad.clear();
    ok.clear();
    for (int j = 1; j <= n; j++) g[j].clear();
    for (int j = i; j < min(q + 1, i + bl); j++) {
      if (tp[j] == 1) {
        bad[f(x[j], y[j])] = 1;
        bad[f(x[j] % n + 1, y[j] % n + 1)] = 1;
      }
    }
    for (int j = 1; j <= n; j++) p[j] = j, h[j] = 0;
    for (int j = 1; j < i; j++) {
      if (tp[j] == 1) ok[{x[j], y[j]}] ^= 1;
    }
    for (auto j : ok) {
      if (!j.second) continue;
      pair<int, int> e = j.first;
      if (!bad.count(e) && get(e.first) != get(e.second))
        unite(e.first, e.second);
    }
    for (auto j : ok) {
      if (!j.second) continue;
      pair<int, int> e = j.first;
      if (bad.count(e) && get(e.first) != get(e.second)) {
        g[get(e.first)].push_back(get(e.second));
        g[get(e.second)].push_back(get(e.first));
      }
    }
    for (int j = i; j < min(q + 1, i + bl); j++) {
      x[j] = (x[j] + last - 1) % n + 1;
      y[j] = (y[j] + last - 1) % n + 1;
      if (tp[j] == 1) {
        if (x[j] > y[j]) swap(x[j], y[j]);
        ok[{x[j], y[j]}] ^= 1;
        if (ok[{x[j], y[j]}]) {
          g[get(x[j])].push_back(get(y[j]));
          g[get(y[j])].push_back(get(x[j]));
        } else {
          int v1(get(x[j])), v2(get(y[j]));
          erase_edge(v1, v2);
          erase_edge(v2, v1);
        }
      } else {
        timer++;
        dfs(get(x[j]));
        last = (u[get(y[j])] == timer);
        printf("%d", last);
      }
    }
  }
  return 0;
}
