#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int n, q;
int p[maxn], siz[maxn];
int type[maxn], X[maxn], Y[maxn];
int now_ans = 0;
vector<pair<int, int> > A[maxn * 4];
vector<pair<pair<pair<int, int>, int>, pair<pair<int, int>, int> > >
    B[maxn * 4];
map<pair<int, int>, int> m;
vector<int> ans;
int Find(int x) { return p[x] == x ? x : Find(p[x]); }
void Union(int id, int x, int y) {
  int xx = Find(x), yy = Find(y);
  if (xx == yy) return;
  if (siz[xx] < siz[yy]) {
    B[id].push_back(make_pair(make_pair(make_pair(x, xx), xx),
                              make_pair(make_pair(y, yy), siz[yy])));
    siz[yy] += siz[xx];
    p[xx] = yy;
  } else {
    B[id].push_back(make_pair(make_pair(make_pair(y, yy), yy),
                              make_pair(make_pair(x, xx), siz[xx])));
    siz[xx] += siz[yy];
    p[yy] = xx;
  }
}
void Undo(int id) {
  for (auto i : B[id]) {
    p[i.first.first.second] = i.first.second;
    siz[i.second.first.second] = i.second.second;
  }
}
void add(int now, int l, int r, int ql, int qr, int x, int y) {
  if (r < ql || l > qr)
    return;
  else if (l >= ql && r <= qr) {
    A[now].push_back(make_pair(x, y));
    return;
  }
  int M = (l + r) >> 1;
  add(now * 2, l, M, ql, qr, x, y);
  add(now * 2 + 1, M + 1, r, ql, qr, x, y);
}
void dfs(int now, int l, int r) {
  for (auto i : A[now]) {
    if (m[make_pair(i.first, i.second)] == 1) Union(now, i.first, i.second);
  }
  if (l == r) {
    if (type[l] == 1) {
      int x = (X[l] + now_ans + n - 1) % n + 1,
          y = (Y[l] + now_ans + n - 1) % n + 1;
      if (x > y) swap(x, y);
      m[make_pair(x, y)] ^= 1;
    } else {
      int x = (X[l] + now_ans + n - 1) % n + 1,
          y = (Y[l] + now_ans + n - 1) % n + 1;
      if (x > y) swap(x, y);
      if (Find(x) == Find(y))
        now_ans = 1;
      else
        now_ans = 0;
      ans.push_back(now_ans);
    }
  }
  int M = (l + r) >> 1;
  if (l != r) dfs(now * 2, l, M);
  if (l != r) dfs(now * 2 + 1, M + 1, r);
  reverse((B[now]).begin(), (B[now]).end());
  Undo(now);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) p[i] = i, siz[i] = 1;
  for (int i = 1; i <= q; i++) {
    cin >> type[i] >> X[i] >> Y[i];
    if (type[i] == 1) {
      if (X[i] > Y[i]) swap(X[i], Y[i]);
      int x = X[i], y = Y[i];
      if (x > y) swap(x, y);
      if (i - m[make_pair(x, y)] - 1 >= 1)
        add(1, 1, q, m[make_pair(x, y)] + 1, i - 1, x, y);
      add(1, 1, q, i, i, x, y);
      m[make_pair(x, y)] = i;
      x = (X[i]) % n + 1, y = Y[i] % n + 1;
      if (x > y) swap(x, y);
      if (x == X[i] && y == Y[i]) continue;
      if (i - m[make_pair(x, y)] - 1 >= 1)
        add(1, 1, q, m[make_pair(x, y)] + 1, i - 1, x, y);
      add(1, 1, q, i, i, x, y);
      m[make_pair(x, y)] = i;
    }
  }
  for (auto i : m) {
    if (m[i.first] != q)
      add(1, 1, q, m[i.first] + 1, q, i.first.first, i.first.second);
  }
  m.clear();
  dfs(1, 1, q);
  for (int i : ans) cout << i;
  cout << '\n';
}
