/*
TASK:bands
LANG:C
*/
#include <stdio.h>
#define min(a, b) (a<b?a:b)
#define max(a, b) (a>b?a:b)
#define MAXM 100005
struct _ftc
{
    int from, to, color;
} ftc[MAXM];
int N, M, nFtc=0;

main()
{
    int i, q, com, a, b, c;
    scanf("%d %d", &N, &M);
    for(i=0; i<M; i++)
    {
        scanf("%d", &com);
        switch(com)
        {
            case 1:
                scanf("%d %d %d", &a, &b, &c);
                ftc[nFtc].from = min(a, b);
                ftc[nFtc].to = max(a, b);
                ftc[nFtc].color = c;
                nFtc++;
                break;
            case 2:
                scanf("%d %d", &a, &b);
                for(q=nFtc-1; q>=0; q--)
                    if(ftc[q].from == min(a, b) && max(a, b) == ftc[q].to)
                    {
                        ftc[q].from = ftc[q].to = 0;
                        break;
                    }
                break;
            case 3:
                scanf("%d", &a);
                for(q=nFtc-1; q>=0; q--)
                    if(ftc[q].from <= a && a < ftc[q].to)
                    {
                        printf("%d\n", ftc[q].color);
                        goto end;
                    }
                printf("0\n");
                end:
                break;
        }
    }
    return 0;
}
