#include <bits/stdc++.h>
using namespace std;
const int SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
struct state {
  int u, v, ru, rv;
  state(int u, int v, int ru, int rk) : u(u), v(v), ru(ru), rv(rv){};
};
struct DSU {
  vector<int> uf, rk;
  stack<state> UPD;
  DSU(int n) : uf(n), rk(n) { iota(uf.begin(), uf.end(), 0); }
  int find(int u) { return u == uf[u] ? u : find(uf[u]); }
  void merge(int u, int v) {
    u = find(u);
    v = find(v);
    if (u != v) {
      if (rk[u] > rk[v]) swap(u, v);
      UPD.emplace(u, v, rk[u], rk[v]);
      uf[u] = v;
      if (rk[u] == rk[v]) rk[v]++;
    } else
      UPD.emplace(-1, 0, 0, 0);
  }
  void rollback() {
    if (!UPD.empty()) {
      state second = UPD.top();
      UPD.pop();
      if (second.u != -1) {
        uf[second.u] = second.u;
        uf[second.v] = second.v;
        rk[second.u] = second.ru;
        rk[second.v] = second.rv;
      }
    }
  }
};
void test_case() {
  int n, m;
  cin >> n >> m;
  int B = sqrt(m) + 1;
  vector<int> op(m), u(m), v(m);
  for (int i = 0; i < m; i++) {
    cin >> op[i] >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    if (u[i] > v[i]) swap(u[i], v[i]);
  }
  string ans;
  int last = 0;
  for (int i = 0; i * B < m; i++) {
    DSU dsu(n);
    int l = i * B, r = min((i + 1) * B - 1, m - 1);
    set<pair<int, int>> second;
    map<pair<int, int>, int> added;
    for (int j = l; j <= r; j++) {
      if (op[j] == 2) continue;
      second.emplace(u[j], v[j]);
      int u1 = (u[j] + 1) % n;
      int v1 = (v[j] + 1) % n;
      if (u1 > v1) swap(u1, v1);
      second.emplace(u1, v1);
    }
    vector<int> k;
    for (int j = 0; j < l; j++) {
      if (op[j] == 1) {
        if (!second.count({u[j], v[j]}))
          dsu.merge(u[j], v[j]);
        else {
          added[{u[j], v[j]}] = (int)k.size();
          k.push_back(j);
        }
      }
    }
    int p = 0;
    for (int j = l; j <= r; j++) {
      u[j] = (u[j] + last) % n;
      v[j] = (v[j] + last) % n;
      if (u[j] > v[j]) swap(u[j], v[j]);
      if (op[j] == 2) {
        while (p < (int)k.size()) {
          if (op[k[p]] == 1)
            dsu.merge(u[k[p]], v[k[p]]);
          else
            dsu.merge(0, 0);
          p++;
        }
        last = (dsu.find(u[j]) == dsu.find(v[j]));
        ans += last + '0';
      }
      if (op[j] == 1) {
        if (added.count({u[j], v[j]})) {
          while (p > added[{u[j], v[j]}]) {
            dsu.rollback();
            p--;
          }
          op[k[added[{u[j], v[j]}]]] = 2;
          op[j] = 2;
          added.erase({u[j], v[j]});
        } else {
          added[{u[j], v[j]}] = (int)k.size();
          k.push_back(j);
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    test_case();
  }
  return 0;
}
