#include <bits/stdc++.h>
using namespace std;
const int K = 700;
const int N = 200010;
int n, m, opt[N], x[N], y[N], last;
set<pair<int, int>> S, s;
vector<int> G[N], g[N];
bool in[N];
int belong[N];
pair<int, int> tmp[(K << 1) + 10];
int qu[N];
void rebuild(int st) {
  for (int i = 1; i <= n; i++) G[i].clear();
  s.clear();
  int cnt = 0;
  for (int i = 1; i <= K; i++) {
    if (st + i > m) break;
    int a = x[st + i], b = y[st + i];
    tmp[++cnt] = make_pair((a - 1) % n + 1, (b - 1) % n + 1);
    tmp[++cnt] = make_pair(a % n + 1, b % n + 1);
  }
  for (int i = 1; i <= cnt; i++)
    if (tmp[i].first > tmp[i].second) swap(tmp[i].first, tmp[i].second);
  sort(tmp + 1, tmp + cnt + 1);
  int now = 1;
  for (const auto& E : S) {
    int x = E.first, y = E.second;
    for (; now <= cnt && tmp[now] < E; now++)
      ;
    if (now <= cnt && E == tmp[now]) {
      s.insert(E);
      now++;
    } else
      G[x].push_back(y), G[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!in[i]) {
      int t;
      qu[t = 1] = i;
      in[i] = 1;
      for (int j = 1; j <= t; j++) {
        int u = qu[j];
        belong[u] = i;
        for (auto k : G[u])
          if (!in[k]) in[qu[++t] = k] = 1;
      }
    }
  for (int i = 1; i <= n; i++) in[i] = 0;
}
void modi(int x, int y) {
  if (x > y) swap(x, y);
  if (S.find(make_pair(x, y)) == S.end())
    S.insert(make_pair(x, y)), s.insert(make_pair(x, y));
  else
    S.erase(make_pair(x, y)), s.erase(make_pair(x, y));
}
int q[N];
void query(int x, int y) {
  last = 0;
  for (const auto& E : s) {
    int a = belong[E.first], b = belong[E.second];
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int t;
  in[q[t = 1] = belong[x]] = 1;
  for (int i = 1; i <= t; i++) {
    int u = q[i];
    if (u == belong[y]) last = 1;
    for (auto j : g[u])
      if (!in[j]) in[q[++t] = j] = 1;
  }
  for (int i = 1; i <= t; i++) in[q[i]] = 0;
  for (const auto& E : s) {
    int a = belong[E.first], b = belong[E.second];
    g[a].clear();
    g[b].clear();
  }
  putchar(last + '0');
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &opt[i], &x[i], &y[i]);
  for (int i = 1; i <= n; i++) belong[i] = i;
  last = 0;
  for (int i = 1; i <= m; i++) {
    int a = (x[i] + last - 1) % n + 1, b = (y[i] + last - 1) % n + 1;
    if (opt[i] == 1)
      modi(a, b);
    else
      query(a, b);
    if (i % K == 0 && i < m) rebuild(i);
  }
  puts("");
  return 0;
}
