#include <iostream>
#include <vector>
#include <map>
using namespace std;

class UnionFind {
public:
    UnionFind(int size) : r(size), p(size)  // 0 origin
    { for (int i = 0; i < size; i++) p[i] = i; }

    int unite(int x, int y) {
        x = find(x), y = find(y);
        if (r[x] > r[y]) swap(x, y);
        else if (r[x] == r[y]) r[y]++;
        return p[x] = y;    // return root
    }

    int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }

    bool same(int x, int y) { return find(x) == find(y); }
    int rank(int x) const { return r[x]; }
    int parent(int x) const { return p[x]; }
private:
    UnionFind();
    vector<int> r, p;
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<map<int, int>> cnt(n);
    for (int i = 0; i < n; i++) {
        int c;
        scanf("%d", &c);
        cnt[i][c - 1] = 1;
    }
    UnionFind uf(n);
    while (q--) {
        int com, a, b;
        scanf("%d%d%d", &com, &a, &b);
        a--, b--;
        if (com == 1) {
            a = uf.find(a);
            b = uf.find(b);
            if (a == b) continue;
            int root = uf.unite(a, b);
            if (root != a) swap(a, b);
            for (auto [c, v] : cnt[b]) cnt[a][c] += v;
        }
        else printf("%d\n", cnt[uf.find(a)][b]);
    }
    return 0;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1.0);
#define sqr(x) ((ll)(x) * (x))
#define reset(a,b) memset(a, b, sizeof(a))
#define ff first
#define int long long
#define ss second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define len(v) (ll)v.size()
#define srt(v) sort( v.begin(), v.end())
#define rsrt(v) sort( v.rbegin(), v.rend())
#define rvrs(v) reverse( v.begin(), v.end())
#define PERMUTE next_permutation
#define tc(t) while (t--)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define ses cout<<"\n"
#define input(x,n) for(int i=0;i<n;i++) cin>>x[i]
#define output(x,n) for(int i=0;i<n;i++) cout<<x[i]<<" "
bool odd(ll n){if(n&1)return true;return false;}
//ll xor(ll a,ll b)return a^b;
ll power(ll x, ll y,ll M){ll res=1;while(y>0){ if(y&1)res=(res*x)%M;y=(y>>1)%M;x=(x*x)%M;}return res;}
constexpr int N = 2e5+5, P = 1000000007;
struct cmp {bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
    int lena = a.second -a.first + 1;int lenb = b.second-b.first + 1;if (lena == lenb) return a.first < b.first;return lena > lenb;
	}
};

bool sortby(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first<b.first);
}
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int mod=1e9+7;
void code()
{

    int x,y;
    cin>>x>>y;
    if(x==y)
        cout<<x;
    else{
       for(int i=0;i<=2;i++)
       {
           if(i!=x&&i!=y)
            {
                cout<<i;return;
            }
       }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    tc(t)
    {
       code();ses;
    }
}

