#include <bits/stdc++.h>
using namespace std;
const int N = 2E5;
const int K = 2000;
set<pair<int, int> > edges;
map<int, int> ccg[N];
int p[N];
int parent(int a) { return p[a] == a ? a : p[a] = parent(p[a]); }
bool join(int a, int b) {
  p[a = parent(a)] = parent(b);
  return p[a] != a;
}
bool dfs(set<int> &vis, int cur, int target) {
  if (vis.find(cur) != vis.end()) return false;
  vis.insert(cur);
  if (cur == target) return true;
  bool res = false;
  for (auto x : ccg[cur]) res |= dfs(vis, x.first, target);
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int> > > q;
  for (int i = 0; i < m; i++) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    x--;
    y--;
    q.push_back({t, {min(x, y), max(x, y)}});
  }
  int last = 0;
  string res = "";
  for (int b = 0; b < (m + K - 1) / K; b++) {
    int block_start = K * b, block_end = min(m, K * (b + 1));
    set<pair<int, int> > potential;
    for (int i = block_start; i < block_end; i++)
      if (q[i].first == 1) {
        potential.insert({q[i].second.first, q[i].second.second});
        pair<int, int> temp = {(q[i].second.first + 1) % n,
                               (q[i].second.second + 1) % n};
        potential.insert(
            {min(temp.first, temp.second), max(temp.first, temp.second)});
      }
    iota(p, p + n, 0);
    for (auto e : edges)
      if (potential.find(e) == potential.end()) join(e.first, e.second);
    for (int i = 0; i < n; i++) ccg[i].clear();
    for (auto e : potential) {
      int x = e.first, y = e.second;
      int ccx = parent(x), ccy = parent(y);
      if (edges.find(e) != edges.end() && ccx != ccy) {
        ccg[ccx][ccy]++;
        ccg[ccy][ccx]++;
      }
    }
    for (int i = block_start; i < block_end; i++) {
      int x = (q[i].second.first + last) % n,
          y = (q[i].second.second + last) % n;
      if (x > y) swap(x, y);
      int ccx = parent(x), ccy = parent(y);
      if (q[i].first == 1) {
        if (edges.find({x, y}) == edges.end()) {
          edges.insert({x, y});
          ccg[ccx][ccy]++;
          ccg[ccy][ccx]++;
        } else {
          edges.erase({x, y});
          ccg[ccx][ccy]--;
          ccg[ccy][ccx]--;
          if (ccg[ccx][ccy] == 0) {
            ccg[ccx].erase(ccy);
            ccg[ccy].erase(ccx);
          }
        }
      } else {
        set<int> vis = {};
        last = dfs(vis, ccx, ccy);
        res += last ? '1' : '0';
      }
    }
  }
  printf("%s\n", res.c_str());
  return 0;
}
