#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 400500, P = 1000;
int n, m, X[N], Y[N], curm, num0[N], num1[N], col[N], cnt[N], used[N], timer,
    fin, type[N], last;
bool ok[N];
vector<pair<int, int> > G, gr[N];
vector<int> g[N];
map<int, int> M[N];
int get(int x, int y) {
  if (x > y) swap(x, y);
  if (!M[x].count(y)) {
    M[x][y] = ++curm;
    G.push_back(make_pair(x, y));
  }
  return M[x][y];
}
bool dfs1(int v) {
  used[v] = timer;
  if (v == fin) return 1;
  for (auto to : gr[v]) {
    if (cnt[to.first] % 2 && used[to.second] != timer)
      if (dfs1(to.second)) return 1;
  }
  return 0;
}
void dfs(int v) {
  for (int to : g[v]) {
    if (!col[to]) {
      col[to] = col[v];
      dfs(to);
    }
  }
}
int main() {
  G.push_back(make_pair(0, 0));
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> type[i] >> X[i] >> Y[i];
    X[i]--, Y[i]--;
    if (type[i] == 2) continue;
    num0[i] = get(X[i], Y[i]);
    num1[i] = get((X[i] + 1) % n, (Y[i] + 1) % n);
  }
  for (int i = 1; i <= m; i += P) {
    memset(ok, 0, sizeof ok);
    memset(col, 0, sizeof col);
    for (int j = i; j <= min(i + P - 1, m); ++j) {
      if (type[j] == 1) ok[num0[j]] = ok[num1[j]] = 1;
    }
    for (int j = 0; j < n; ++j) g[j].clear(), gr[j].clear();
    for (int j = 1; j <= curm; ++j)
      if (!ok[j] && (cnt[j] & 1)) {
        int x = G[j].first, y = G[j].second;
        g[x].push_back(y);
        g[y].push_back(x);
      }
    int comp = 0;
    for (int j = 0; j < n; ++j) {
      if (!col[j]) {
        col[j] = ++comp;
        dfs(j);
      }
    }
    for (int j = 1; j <= curm; ++j)
      if (ok[j] && col[G[j].first] != col[G[j].second])
        gr[col[G[j].first]].push_back(make_pair(j, col[G[j].second])),
            gr[col[G[j].second]].push_back(make_pair(j, col[G[j].first]));
    for (int j = i; j <= min(i + P - 1, m); ++j) {
      if (type[j] == 1) {
        if (last == 0) {
          cnt[num0[j]]++;
        } else {
          cnt[num1[j]]++;
        }
      } else {
        int x = X[j], y = Y[j];
        if (last) x = (x + 1) % n, y = (y + 1) % n;
        if (col[x] != col[y]) {
          timer++;
          fin = col[y];
          if (dfs1(col[x]))
            last = 1;
          else
            last = 0;
        } else
          last = 1;
        cout << last;
      }
    }
  }
  return 0;
}
