#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t[N], x[N], y[N], par[N], sz[N], pnt[N << 1], E[N << 1][2], n, m, last, ne;
bool mark[N << 1];
vector<int> pos[N << 1], seg[N << 2];
vector<pair<int, int> > ST;
map<pair<int, int>, int> mp;
pair<int, int> mpr(int i, int j) {
  if (i > j) swap(i, j);
  return make_pair(i, j);
}
int getpar(int v) { return (par[v] == v ? v : getpar(par[v])); }
void Union(int u, int v) {
  u = getpar(u), v = getpar(v);
  if (u == v) {
    ST.push_back({0, 0});
    return;
  }
  if (sz[u] > sz[v]) swap(u, v);
  par[u] = par[v], sz[v] += sz[u];
  ST.push_back({v, u});
  return;
}
void Undo() {
  int v = ST.back().first, u = ST.back().second;
  ST.pop_back();
  if (v == 0) return;
  sz[v] -= sz[u], par[u] = u;
  return;
}
void Add(int l, int r, int e, int L = 0, int R = m, int id = 1) {
  if (r <= L || R <= l) return;
  if (l <= L && R <= r) {
    seg[id].push_back(e);
    return;
  }
  int mid = (L + R) >> 1;
  Add(l, r, e, L, mid, id << 1), Add(l, r, e, mid, R, id << 1 | 1);
  return;
}
void Solve(int L = 0, int R = m, int id = 1) {
  for (int e : seg[id]) Union(E[e][0], E[e][1]);
  if (R - L == 1) {
    if (t[L] == 1) {
      mark[mp[mpr((x[L] + last - 1) % n + 1, (y[L] + last - 1) % n + 1)]] ^= 1;
      int e = mp[mpr(x[L], y[L])];
      if (mark[e]) Add(pos[e][pnt[e]] + 1, pos[e][pnt[e] + 1], e);
      pnt[e]++;
      e = mp[mpr(x[L] % n + 1, y[L] % n + 1)];
      if (mark[e]) Add(pos[e][pnt[e]] + 1, pos[e][pnt[e] + 1], e);
      pnt[e]++;
    } else
      cout << (last = getpar((x[L] + last - 1) % n + 1) ==
                      getpar((y[L] + last - 1) % n + 1));
    for (int i = 0; i < ((int)seg[id].size()); i++) Undo();
    return;
  }
  int mid = (L + R) >> 1;
  Solve(L, mid, id << 1), Solve(mid, R, id << 1 | 1);
  for (int i = 0; i < ((int)seg[id].size()); i++) Undo();
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
  for (int i = 0; i < m; i++) {
    cin >> t[i] >> x[i] >> y[i];
    if (t[i] == 1) {
      if (!mp[mpr(x[i], y[i])])
        mp[mpr(x[i], y[i])] = ++ne, E[ne][0] = x[i], E[ne][1] = y[i];
      if (!mp[mpr(x[i] % n + 1, y[i] % n + 1)])
        mp[mpr(x[i] % n + 1, y[i] % n + 1)] = ++ne, E[ne][0] = x[i] % n + 1,
                                        E[ne][1] = y[i] % n + 1;
      pos[mp[mpr(x[i], y[i])]].push_back(i);
      pos[mp[mpr(x[i] % n + 1, y[i] % n + 1)]].push_back(i);
    }
  }
  for (int i = 1; i <= ne; i++) pos[i].push_back(m);
  Solve();
  return cout << "\n", 0;
}
