#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const int INF = 1e9;
const long long MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n, q, P[N], S[N], T[N], X[N][2], Y[N][2];
bool last;
map<int, int> L[N], M[N];
int NXT[N][2];
vector<pair<int, int> > SEG[N << 2];
stack<int> ST;
void Add(int l, int r, pair<int, int> p, int id = 1, int s = 0, int e = q) {
  if (l >= e || s >= r) return;
  if (l <= s && e <= r) {
    SEG[id].push_back(p);
    return;
  }
  Add(l, r, p, id << 1, s, (s + e) >> 1),
      Add(l, r, p, id << 1 ^ 1, (s + e) >> 1, e);
}
int GetPar(int v) { return P[v] == v ? v : GetPar(P[v]); }
bool Merge(int v, int u) {
  v = GetPar(v), u = GetPar(u);
  if (v == u) return 0;
  if (S[v] < S[u]) swap(v, u);
  P[u] = v;
  S[v] += S[u];
  ST.push(u);
  return 1;
}
void Undo() {
  assert(!ST.empty());
  int u = ST.top(), v = P[u];
  ST.pop();
  P[u] = u, S[v] -= S[u];
}
void DFS(int id = 1, int s = 0, int e = q) {
  int cnt = 0;
  for (auto [v, u] : SEG[id]) cnt += Merge(v, u);
  if (e - s < 2) {
    if (T[s] == 1) {
      M[X[s][last]][Y[s][last]] ^= 1;
      for (int b = 0; b < 2; b++) {
        int x = X[s][b], y = Y[s][b];
        if (M[x][y]) Add(s + 1, NXT[s][b], make_pair(x, y));
      }
    } else
      last = (GetPar(X[s][last]) == GetPar(Y[s][last])), cout << last;
  } else
    DFS(id << 1, s, (s + e) >> 1), DFS(id << 1 ^ 1, (s + e) >> 1, e);
  while (cnt--) Undo();
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  mt19937 Rnd(time(0));
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i] >> X[i][0] >> Y[i][0];
    X[i][1] = X[i][0] % n + 1, Y[i][1] = Y[i][0] % n + 1;
  }
  for (int i = q - 1; i >= 0; i--)
    if (T[i] == 1) {
      for (int b = 0; b < 2; b++) {
        int &x = X[i][b], &y = Y[i][b];
        if (x > y) swap(x, y);
        if (!L[x].count(y)) L[x][y] = q;
        NXT[i][b] = L[x][y];
        L[x][y] = i;
      }
    }
  for (int i = 1; i <= n; i++) P[i] = i, S[i] = 1;
  DFS();
  cout << '\n';
  return 0;
}
