#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)

const int max_n = 2e5+5;
int n, q, c[max_n], par[max_n], num[max_n];
map<int, int> mp[max_n];
void init() {
	rep(i,1,n){
		par[i] = i;
        mp[i].insert({c[i], 1});
	}
}
int ufind(int x){
	if(par[x] == x) return x;
	else {
		int um = ufind(par[x]);
		return par[x] = um;
	}
}
void unite(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x == y) return;
	if(mp[x].size() < mp[y].size()) swap(x, y);
	par[y] = x;
	num[x] += num[y];
    num[y] = 0;
    for(auto i = mp[y].begin(); i != mp[y].end(); i++)
        mp[x][i->first] += i->second;
    mp[y].clear();
}

int main() {
    cin >> n >> q;
    rep(i, 1, n){
        cin >> c[i];
    }
    init();
    rep(qs, 1, q){
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 1) unite(a, b);
        if(t == 2) cout << mp[ufind(a)][b] << endl;
    }
    return 0;
}
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

#define	INF   1010101010
#define INFLL 1010101010101010101

using namespace std;

int mod = 1000000007;

class Union_Find {
public:
	Union_Find(int n) : d(n, -1) {}

	int find(int x)
	{
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-d[x] < -d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}

	int size(int x)
	{
		return -d[find(x)];
	}

private:
	vector<int> d;
};

int main()
{
	int n, q;
	cin >> n >> q;
	Union_Find uf(n);
	vector<map<int, int>> m(n);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		t--;
		m[i][t]++;
	}
	
	for (int i = 0; i < q; i++) {
		int t, a, b;
		cin >> t >> a >> b;
		a--;
		b--;
		if (t == 1) {
			int na = uf.size(a), nb = uf.size(b);
			int pa = uf.find(a), pb = uf.find(b);
			if (uf.unite(a, b)) {
				if (na < nb) {
					for (auto &j : m[pa]) {
						m[pb][j.first] += j.second;
					}
				} else {
					for (auto &j : m[pb]) {
						m[pa][j.first] += j.second;
					}
				}
			}
		} else {
			cout << m[uf.find(a)][b] << endl;
		}
	}

	return 0;
}