using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace cf207
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf207B();
        }

        public static void solve_cf207B()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = nm[0];
            int m = nm[1];

            Dictionary<char, int> dic = new Dictionary<char, int>();
            for (int i = 0; i < m; i++)
            {
                string[] row = Console.ReadLine().Split(' ');

                int k = 0;
                for (int j = 0; j < row.Length; j++)
                {
                    if (dic.ContainsKey(row[j][0]))
                    {
                        k = dic[row[j][0]];
                    }
                    else
                    {
                        dic.Add(row[j][0], (k % 3) + 1);
                        k++;
                    }
                }
            }

            var sortedDic = dic.OrderBy(a => a.Key).ToList();
            foreach (KeyValuePair<char, int> pair in sortedDic)
            {
                Console.Write("{0} ", pair.Value);
            }
        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace cf207
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf207B();
        }

        public static void solve_cf207B()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = nm[0];
            int m = nm[1];

            Dictionary<char, int> dic = new Dictionary<char, int>();

            for (int i = 0; i < m; i++)
            {
                string[] row = Console.ReadLine().Split(' ');

                List<char> t = new List<char>();
                char usedK = char.MinValue;
                int usedV = 0;
                for (int j = 0; j < row.Length; j++)
                {
                    if (dic.ContainsKey(row[j][0]))
                    {
                        usedK = row[j][0];
                        usedV = dic[row[j][0]];
                    }
                    t.Add(row[j][0]);
                }

                for (int j = 0; j < t.Count; j++)
                {
                    if (t[j] != usedK)
                    {
                        dic.Add(t[j], (usedV % 3) + 1);
                        usedV = (usedV % 3) + 1;
                    }
                }
            }

            var sortedDic = dic.OrderBy(a => a.Key).ToList();
            foreach (KeyValuePair<char, int> pair in sortedDic)
            {
                Console.Write("{0} ", pair.Value);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Codeforces
{
	public class B
	{
		public static int Main()
		{
			int [] input = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
			int n = input[0];
			int m = input[1];

			int [] color = new int[n + 1];

			while (m-->0)
			{
				int [] dance = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
				bool [] hasColor = new bool[dance.Length];
				bool [] colorTaken = new bool[4];
				for (int i = 0; i < dance.Length; ++i)
				{
					hasColor[i] = color[dance[i]] != 0;
					if (hasColor[i])
					{
//						Console.WriteLine("taken {0}", color[dance[i]]);
						colorTaken[color[dance[i]]] = true;
					}
				}
				for (int i = 0; i < dance.Length; ++i)
				{
					if (hasColor[i]) continue;
					for (int c = 1; c <= 3; ++c)
					{
						if (colorTaken[c]) continue;
//						Console.WriteLine("taken {0}", dance[i]);
						color[dance[i]] = c;
						colorTaken[c] = true;
						hasColor[i] = true;
						break;
					}
				}
//			/	Console.WriteLine();
			}
			for (int i = 1; i <= n; ++i) Console.Write("{0} ", color[i]);

			return 0;
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Codeforces
{
	public class B
	{
		public static int Main()
		{
			int [] input = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
			int n = input[0];
			int m = input[1];

			int [] color = new int[n + 1];
			Tuple<int, int> [] rank = new Tuple<int, int>[n + 1];
			for (int i = 1; i <= n; ++i) rank[i] = new Tuple<int, int>(0, i);

			List<int> [] Adj = new List<int>[n + 1];
			for (int i = 1; i <= n; ++i) Adj[i] = new List<int>();

			while (m-->0)
			{
				int [] dance = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
				Adj[dance[0]].Add(dance[1]);
				Adj[dance[0]].Add(dance[2]);
				Adj[dance[1]].Add(dance[0]);
				Adj[dance[1]].Add(dance[2]);
				Adj[dance[2]].Add(dance[0]);
				Adj[dance[2]].Add(dance[1]);
				rank[dance[0]] = new Tuple<int, int>(rank[dance[0]].Item1 + 1, rank[dance[0]].Item2);
				rank[dance[1]] = new Tuple<int, int>(rank[dance[1]].Item1 + 1, rank[dance[1]].Item2);
				rank[dance[2]] = new Tuple<int, int>(rank[dance[2]].Item1 + 1, rank[dance[2]].Item2);
			}

			Array.Sort(rank);
			Array.Reverse(rank, 1, n);

			for (int i = 1; i <= n; ++i)
			{
				for (int c = 1; c <= 3; ++c)
				{
					bool good = true;
					foreach (var j in Adj[i])
					{
						if (color[j] == c)
						{
							good = false;
							break;
						}
					}
					if (!good) continue;
					color[i] = c;
					break;
				}
			}

			for (int i = 1; i <= n; ++i) Console.Write("{0} ", color[i]);

			return 0;
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Codeforces
{
	public class B
	{
		public static int Main()
		{
			int [] input = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
			int n = input[0];
			int m = input[1];

			int [] color = new int[n + 1];
			Tuple<int, int> [] rank = new Tuple<int, int>[n + 1];
			for (int i = 1; i <= n; ++i) rank[i] = new Tuple<int, int>(0, i);

			List<int> [] Adj = new List<int>[n + 1];
			for (int i = 1; i <= n; ++i) Adj[i] = new List<int>();

			while (m-->0)
			{
				int [] dance = Console.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
				Adj[dance[0]].Add(dance[1]);
				Adj[dance[0]].Add(dance[2]);
				Adj[dance[1]].Add(dance[0]);
				Adj[dance[1]].Add(dance[2]);
				Adj[dance[2]].Add(dance[0]);
				Adj[dance[2]].Add(dance[1]);
				rank[dance[0]] = new Tuple<int, int>(rank[dance[0]].Item1 + 1, rank[dance[0]].Item2);
				rank[dance[1]] = new Tuple<int, int>(rank[dance[1]].Item1 + 1, rank[dance[1]].Item2);
				rank[dance[2]] = new Tuple<int, int>(rank[dance[2]].Item1 + 1, rank[dance[2]].Item2);
			}

			Array.Sort(rank);
			Array.Reverse(rank, 1, n);

//			for (int i = 1; i <= n; ++i)
//			{
//				Console.WriteLine("{0} {1}", rank[i].Item1, rank[i].Item2);
//			}
//			Console.WriteLine();

			for (int i = 1; i <= n; ++i)
			{
				int u = rank[i].Item2;
				for (int c = 1; c <= 3; ++c)
				{
					bool good = true;
					foreach (var v in Adj[u])
					{
						if (color[v] == c)
						{
							good = false;
							break;
						}
					}
					if (!good) continue;
//					Console.WriteLine("Assigned color {0} to {1}", c, u);
					color[u] = c;
					break;
				}
			}

			for (int i = 1; i <= n; ++i) Console.Write("{0} ", color[i]);

			return 0;
		}
	}
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

    fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next::<T>()).collect()
    }
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let m: usize = scan.next();
    let mut assigned = [0usize; 100001];
    for _ in 0..m {
        let dance: Vec<usize> = scan.next_n(3);
        let mut used = [false; 4];
        used[0] = true;
        for i in dance.iter() {
            let color = assigned[*i];
            used[color] = true;
        }
        for i in dance.iter() {
            if assigned[*i] == 0 {
                let color: usize = used.iter().position(|x| *x == false).unwrap();
                assigned[*i] = color;
                used[color] = true;
            }
        }
    }
    for i in 1..=n {
        print!("{} ", if assigned[i] != 0 { assigned[i] } else { 1 });
    }
    println!();
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


package main
import (
	"fmt"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var v [1111111]int
	var i,j,n,m,k int
	fmt.Scan(&n,&m)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	var a,b [5]int
	out := bufio.NewWriter(os.Stdout)
	for i=1;i<=m; i++{
		t:=0
		for j=1;j<=3;j++{
			input.Scan()
			aa,_:=strconv.Atoi(input.Text())
			b[i]=aa
			//fmt.Scan(&b[j])
			if v[b[j]]!=0 {t=b[j]}
		}
		a[1],a[2],a[3] = 0,0,0
		if t!=0 { a[v[t]] =1}

		for j=1;j<=3;j++{
			if v[b[j]]!=0 { continue }
			for k=1;k<=3;k++{
				if a[k]!=0 { continue}
				v[b[j]] = k
				a[k] = 1
				break
			}
		}
	}
	for i=1;i<=n;i++{
		out.WriteString(strconv.Itoa(v[i])+" ")
	}
	out.Flush()
}


package main
import (
	"fmt"
	//"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var v [1111111]int
	var i,j,n,m,k int
	fmt.Scan(&n,&m)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	var a,b [5]int
	out := bufio.NewWriter(os.Stdout)
	for i=1;i<=m; i++{
		t:=0
		for j=1;j<=3;j++{
			input.Scan()
			aa,_:=strconv.Atoi(input.Text())
			b[i]=aa
			//fmt.Scan(&b[j])
			if v[b[j]]!=0 {t=b[j]}
		}
		a[1],a[2],a[3] = 0,0,0
		if t!=0 { a[v[t]] =1}

		for j=1;j<=3;j++{
			if v[b[j]]!=0 { continue }
			for k=1;k<=3;k++{
				if a[k]!=0 { continue}
				v[b[j]] = k
				a[k] = 1
				break
			}
		}
	}
	for i=1;i<=n;i++{
		out.WriteString(strconv.Itoa(v[i])+" ")
	}
	out.Flush()
}


package main
import (
	"fmt"
	//"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var v [1111111]int
	var i,j,n,m,k int
	fmt.Scan(&n,&m)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	var a,b [5]int
	out := bufio.NewWriter(os.Stdout)
	for i=1;i<=m; i++{
		t:=0
		for j=1;j<=3;j++{
			input.Scan()
			aa,_:=strconv.Atoi(input.Text())
			b[j]=aa
			//fmt.Scan(&b[j])
			if v[b[j]]!=0 {t=b[j]}
		}
		a[1],a[2],a[3] = 0,0,0
		if t!=0 { a[v[t]] =1}

		for j=1;j<=3;j++{
			if v[b[j]]!=0 { continue }
			for k=1;k<=3;k++{
				if a[k]!=0 { continue}
				v[b[j]] = k
				a[k] = 1
				break
			}
		}
	}
	for i=1;i<=n;i++{
		out.WriteString(strconv.Itoa(v[i])+" ")
	}
	out.Flush()
}


package main
import (
	"fmt"
)

func main() {
	var v [1111111]int
	var i,j,n,m,k int
	fmt.Scan(&n,&m)
	var a,b [5]int
	for i=1;i<=m; i++{
		t:=0
		for j=1;j<=3;j++{
			fmt.Scan(&b[j])
			if v[b[j]]!=0 {t=b[j]}
		}
		a[1],a[2],a[3] = 0,0,0
		if t!=0 { a[v[t]] =1}

		for j=1;j<=3;j++{
			if v[b[j]]!=0 { continue }
			for k=1;k<=3;k++{
				if a[k]!=0 { continue}
				v[b[j]] = k
				a[k] = 1
				break
			}
		}
	}
	for i=1;i<=n;i++{
		fmt.Print(v[i]," ") ;
	}
}


#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(m):
    n=1
    primes = {}
    arr=set([])
    for i in range(2, int(m ** 0.5) + 1):
        a = n // i
        b = m // i
        for k in range(max(2, a), b + 1):
            c = i * k
            primes[c] = 1

    for i in range(max(n, 2), m + 1):
        if i not in primes:
            arr.add(i)

    return arr

def nc2(x):
    return (x*(x-1))//2
class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n

    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a

            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets

def cnt(x,n):
    if x>n:
        return 0
    return (1+cnt(10*x,n)+cnt(10*x+1,n))
def main():
    n,m = map(int,input().split())
    mydict = dict()
    ans = [0]*n
    mydict2 = {1:[2,3],2:[1,3],3:[1,2]}
    for i in range(m):
        a,b,c = map(int,input().split())
        if a in mydict:
            x = mydict[a]
            ans[b-1] = mydict2[x][0]
            ans[c-1] = mydict2[x][1]
            mydict[b] = ans[b-1]
            mydict[c] = ans[c-1]
        elif b in mydict:
            x = mydict[b]
            ans[a - 1] = mydict2[x][0]
            ans[c - 1] = mydict2[x][1]
            mydict[a] = ans[a - 1]
            mydict[c] = ans[c - 1]
        elif c in mydict:
            x = mydict[c]
            ans[b - 1] = mydict2[x][0]
            ans[a - 1] = mydict2[x][1]
            mydict[b] = ans[b - 1]
            mydict[a] = ans[a - 1]
        else:
            ans[a-1],mydict[a] = 1,1
            ans[b-1],mydict[b] = 2,2
            ans[c-1],mydict[c] = 3,3
    print(*ans)

    # arr=list(map(int,input().strip().split()))
    # cnt=0
    # for i in arr:
    #     if i%4!=2 and i not in [1,2,4]:
    #         cnt+=1
    # print(cnt)

# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


n, m = map(int, input().split())
red = set(); blue = set(); white = set()
for i in range(m):
    x, y, z = map(int, input().split())
    if x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in blue:
                blue.add(y)
        else:
            blue.add(y)
            red.add(z)
    elif x in red:
        if y in blue:
            if z not in white:
                white.add(z)
        elif y in white:
            if z not in blue:
                blue.add(z)
        elif z in white:
            if y not in blue:
                blue.add(y)
        elif z in blue:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            white.add(z)
    elif x in blue:
        if y in white:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in white:
                white.add(z)
        elif z in white:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in white:
                white.add(y)
        else:
            white.add(y)
            red.add(z)
    else:
        if y in red:
            if z in blue:
                white.add(x)
            elif z in white:
                blue.add(x)
            else:
                white.add(x)
                blue.add(z)
        elif y in white:
            if z in blue:
                red.add(x)
            elif z in red:
                blue.add(x)
            else:
                blue.add(x)
                red.add(z)
        elif y in blue:
            if z in red:
                white.add(x)
            elif z in white:
                red.add(x)
            else:
                red.add(x)
                white.add(z)
        else:
            if z in red:
                white.add(x)
                blue.add(y)
            elif z in white:
                red.add(x)
                blue.add(y)
            elif z in blue:
                red.add(x)
                white.add(y)
            else:
                white.add(x)
                red.add(y)
                blue.add(z)
for i in range(1, n + 1):
    if i in white:
        print(1, end = ' ')
    elif i in red:
        print(2, end = ' ')
    else:
        print(3, end = ' ')


n, m = map(int, input().split())
red = set(); blue = set(); white = set()
for i in range(m):
    x, y, z = map(int, input().split())
    if x in red:
        if y in blue:
            if z not in white:
                white.add(z)
        elif y in white:
            if z not in blue:
                blue.add(z)
        elif z in white:
            if y not in blue:
                blue.add(y)
        elif z in blue:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            white.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in blue:
                blue.add(y)
        else:
            blue.add(y)
            red.add(z)
    elif x in blue:
        if y in white:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in white:
                white.add(z)
        elif z in white:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            red.add(z)
    else:
        red.add(x)
        blue.add(y)
        white.add(z)
for i in range(1, n + 1):
    if i in white:
        print(1, end = ' ')
    elif i in red:
        print(2, end = ' ')
    else:
        print(3, end = ' ')


n, m = map(int, input().split())
red = set(); blue = set(); white = set()
for i in range(m):
    x, y, z = map(int, input().split())
    if x in red:
        if y in blue:
            if z not in white:
                white.add(z)
        elif y in white:
            if z not in blue:
                blue.add(z)
        elif z in white:
            if y not in blue:
                blue.add(y)
        elif z in blue:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            white.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(z)
        elif z in red:
            if y not in blue:
                blue.add(z)
        else:
            blue.add(y)
            red.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(z)
        elif z in red:
            if y not in blue:
                blue.add(z)
        else:
            blue.add(y)
            red.add(z)
    else:
        red.add(x)
        blue.add(y)
        white.add(z)
for i in range(1, n + 1):
    if i in white:
        print(1, end = ' ')
    elif i in red:
        print(2, end = ' ')
    else:
        print(3, end = ' ')


n, m = map(int, input().split())
red = set(); blue = set(); white = set()
for i in range(m):
    x, y, z = map(int, input().split())
    if x in red:
        if y in blue:
            if z not in white:
                white.add(z)
        elif y in white:
            if z not in blue:
                blue.add(z)
        elif z in white:
            if y not in blue:
                blue.add(y)
        elif z in blue:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            white.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in blue:
                blue.add(y)
        else:
            blue.add(y)
            red.add(z)
    elif x in blue:
        if y in white:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in white:
                white.add(z)
        elif z in white:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in white:
                white.add(y)
        else:
            white.add(y)
            red.add(z)
    else:
        red.add(x)
        blue.add(y)
        white.add(z)
for i in range(1, n + 1):
    if i in white:
        print(1, end = ' ')
    elif i in red:
        print(2, end = ' ')
    else:
        print(3, end = ' ')


n, m = map(int, input().split())
red = set(); blue = set(); white = set()
for i in range(m):
    x, y, z = map(int, input().split())
    if x in red:
        if y in blue:
            if z not in white:
                white.add(z)
        elif y in white:
            if z not in blue:
                blue.add(z)
        elif z in white:
            if y not in blue:
                blue.add(y)
        elif z in blue:
            if y not in white:
                white.add(y)
        else:
            blue.add(y)
            white.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in blue:
                blue.add(y)
        else:
            blue.add(y)
            red.add(z)
    elif x in white:
        if y in blue:
            if z not in red:
                red.add(z)
        elif y in red:
            if z not in blue:
                blue.add(z)
        elif z in blue:
            if y not in red:
                red.add(y)
        elif z in red:
            if y not in blue:
                blue.add(y)
        else:
            blue.add(y)
            red.add(z)
    else:
        red.add(x)
        blue.add(y)
        white.add(z)
for i in range(1, n + 1):
    if i in white:
        print(1, end = ' ')
    elif i in red:
        print(2, end = ' ')
    else:
        print(3, end = ' ')


n, m = map(int, input().split())
d = {}
for _ in range(m):
    a = list(map(int, input().split()))
    s = [3, 2, 1]
    for i in a:  # w r b
        if i not in d:
            d[i] = s.pop()
        else:
            if d[i] in s: s.pop(s.index(d[i]))
        #print(d)
    #print('worked', a)
print(*[d[i] for i in sorted(d)])


n, m = map(int, input().split())
d = [-1 for i in range(n + 1)]
for _ in range(m):
	p = {1, 2, 3}
	for i in map(int, input().split()):
		if d[i] == -1:
			d[i] = p.pop()
		else:
			p.discard(d[i])
for j in range(1, n + 1):
	print(d[j], end=' ')


n, m = map(int, input().split())
d = {}
for _ in range(m):
    a = list(map(int, input().split()))
    s = [3, 2, 1]
    for i in a: # w r b
        if i not in d:
            d[i] = s.pop()
        else:
            s.pop(3 - d[i])
print(*[d[i] for i in sorted(d)])


n, m = map(int, input().split())
d = [-1 for i in range(n + 1)]
for _ in range(m):
	p = {1, 2, 3}
	t = list(map(int, input().split()))
	for i in t:
		if d[i] != -1:
			p.discard(d[i])
	for i in t:
		if d[i] == -1:
			d[i] = p.pop()
for j in range(1, n + 1):
	print(d[j], end=' ')


n,m=map(int,input().split())
D=[0]*(10**5+1)
Dancers=[]
diff=[]
for i in range(m):
    a,b,c=map(int,input().split())
    if i==0:
        D[a]=1
        D[b]=2
        D[c]=3
    else:
        num=[1,2,3]
        d=[a,b,c]
        m1=[D[a],D[b],D[c]]
        while 0 in m1:
            for s in num:
                if s not in[D[a],D[b],D[c]]:
                    D[d[m1.index(0)]]=s
                    m1[m1.index(0)]=s
    if a not in diff:
        diff.append(a)
    if b not in diff :
        diff.append(b)
    if c not in diff :
        diff.append(c)
    Dancers.append([a,b,c])
diff.sort()
for i in diff:
    print(D[i],end=' ')


n,m=map(int,input().split())
D=[0]*(10**5+1)
Dancers=[]
diff=[0]*(10**5+1)
for i in range(m):
    a,b,c=map(int,input().split())
    if i==0:
        D[a]=1
        D[b]=2
        D[c]=3
    else:
        if D[a]==0 :
            if 1 not in [D[b],D[c]]:
                D[a]=1
            elif 2 not in [D[b],D[c]]:
                D[a]=2
            else:
                D[a]=3
        if D[b]==0 :
            if 1 not in [D[a],D[c]]:
                D[b]=1
            elif 2 not in [D[a],D[c]]:
                D[b]=2

            else:
                D[b]=3
        if D[c]==0 :
            if 1 not in [D[b],D[a]]:
                D[c]=1
            elif 2 not in [D[b],D[a]]:
                D[c]=2
            else:
                D[c]=3
    diff[a],diff[b],diff[c]=1,1,1
    Dancers.append([a,b,c])

for i in range(len(diff)):
    if diff[i]!=0:
      print(D[i],end=' ')


n,m = list(map(int,input().split()))
colors = [0]*n

for i in range(m):
    choices = [1,2,3]
    dancers = list(map(int,input().split()))
    for a in dancers:
        try:
            choices.remove(colors[a-1])
        except:
            pass
    for a in dancers:
        if(colors[a-1]==0):
            colors[a-1] = choices[0]
            choices.remove(colors[a-1])
print(*colors)


n,m = list(map(int,input().split()))
colors = [0]*n

for i in range(m):
    choices = [1,2,3]
    dancers = list(map(int,input().split()))
    for a in dancers:
        if(colors[a-1]==0):
            colors[a-1] = choices[0]
            choices.remove(colors[a-1])
        else:
            choices.remove(colors[a-1])
print(*colors)


from collections import defaultdict
def main():
    (n, m) = map(int, input().split(' '))
    colors = [0] * (n + 1)
    dances = []
    ma = defaultdict(int)
    for i in range(m):
        (a, b, c) = map(int, input().split(' '))
        ma[a] += 1
        ma[b] += 1
        ma[c] += 1
        dances.append((a, b, c))
    for (a, b, c) in dances:
        if colors[a] == 0 and colors[b] == 0 and colors[c] == 0:
            colors[a] = 1
            colors[b] = 2
            colors[c] = 3
        elif colors[a] != 0 and colors[b] != 0:
            colors[c] = 6 - colors[a] - colors[b]
        elif colors[a] != 0 and colors[c] != 0:
            colors[b] = 6 - colors[a] - colors[c]
        elif colors[b] != 0 and colors[c] != 0:
            colors[a] = 6 - colors[a] - colors[b]
        elif colors[a] != 0:
            if colors[a] == 1:
                colors[b] = 2
                colors[c] = 3
            elif colors[a] == 2:
                colors[b] = 1
                colors[c] = 3
            else:
                colors[b] = 1
                colors[c] = 2
        elif colors[b] != 0:
            if colors[b] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[b] == 2:
                colors[a] = 1
                colors[c] = 3
            else:
                colors[a] = 1
                colors[c] = 2
        elif colors[c] != 0:
            if colors[c] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[c] == 2:
                colors[a] = 1
                colors[b] = 3
            else:
                colors[a] = 1
                colors[b] = 2

    print(' '.join(list(map(str, colors[1:]))))

main()


def main():
    (n, m) = map(int, input().split(' '))
    colors = [0] * (n + 1)
    dances = []
    for i in range(m):
        (a, b, c) = map(int, input().split(' '))
        dances.append((a, b, c))
    for (a, b, c) in dances:
        if colors[a] == 0 and colors[b] == 0 and colors[c] == 0:
            colors[a] = 1
            colors[b] = 2
            colors[c] = 3
        elif colors[a] != 0 and colors[b] != 0:
            colors[c] = 6 - colors[a] - colors[b]
        elif colors[a] != 0 and colors[c] != 0:
            colors[b] = 6 - colors[a] - colors[c]
        elif colors[b] != 0 and colors[c] != 0:
            colors[a] = 6 - colors[a] - colors[b]
        elif colors[a] != 0:
            if colors[a] == 1:
                colors[b] = 2
                colors[c] = 3
            elif colors[a] == 2:
                colors[b] = 1
                colors[c] = 3
            else:
                colors[b] = 1
                colors[c] = 2
        elif colors[b] != 0:
            if colors[b] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[b] == 2:
                colors[a] = 1
                colors[c] = 3
            else:
                colors[a] = 1
                colors[c] = 2
        elif colors[c] != 0:
            if colors[c] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[c] == 2:
                colors[a] = 1
                colors[b] = 3
            else:
                colors[a] = 1
                colors[b] = 2
    s = set()
    for i in range(1, n + 1):
        if colors[i] == 0:
            if 1 in s and 2 in s:
                colors[i] = 3
            elif 1 in s and 3 in s:
                colors[i] = 2
            elif 2 in s and 3 in s:
                colors[i] = 1
            elif 2 in s:
                colors[i] = 3
            elif 1 in s:
                colors[i] = 3
            else:
                colors[i] = 2

    print(' '.join(list(map(str, colors[1:]))))

main()


def main():
    (n, m) = map(int, input().split(' '))
    colors = [0] * (n + 1)
    dances = []
    for i in range(m):
        (a, b, c) = map(int, input().split(' '))
        dances.append((a, b, c))
    for (a, b, c) in dances:
        if colors[a] == 0 and colors[b] == 0 and colors[c] == 0:
            colors[a] = 1
            colors[b] = 2
            colors[c] = 3
        elif colors[a] != 0 and colors[b] != 0:
            colors[c] = 6 - colors[a] - colors[b]
        elif colors[a] != 0 and colors[c] != 0:
            colors[b] = 6 - colors[a] - colors[c]
        elif colors[b] != 0 and colors[c] != 0:
            colors[a] = 6 - colors[a] - colors[b]
        elif colors[a] != 0:
            if colors[a] == 1:
                colors[b] = 2
                colors[c] = 3
            elif colors[a] == 2:
                colors[b] = 1
                colors[c] = 3
            else:
                colors[b] = 1
                colors[c] = 2
        elif colors[b] != 0:
            if colors[b] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[b] == 2:
                colors[a] = 1
                colors[c] = 3
            else:
                colors[a] = 1
                colors[c] = 2
        elif colors[c] != 0:
            if colors[c] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[c] == 2:
                colors[a] = 1
                colors[b] = 3
            else:
                colors[a] = 1
                colors[b] = 2
    print(' '.join(list(map(str, colors[1:]))))

main()


def main():
    (n, m) = map(int, input().split(' '))
    colors = [0] * (n + 1)
    dances = []
    for i in range(m):
        (a, b, c) = map(int, input().split(' '))
        dances.append((a, b, c))
    for (a, b, c) in dances:
        if colors[a] == 0 and colors[b] == 0 and colors[c] == 0:
            colors[a] = 1
            colors[b] = 2
            colors[c] = 3
        elif colors[a] != 0 and colors[b] != 0:
            colors[c] = 6 - colors[a] - colors[b]
        elif colors[a] != 0 and colors[c] != 0:
            colors[b] = 6 - colors[a] - colors[c]
        elif colors[b] != 0 and colors[c] != 0:
            colors[a] = 6 - colors[a] - colors[b]
        elif colors[a] != 0:
            if colors[a] == 1:
                colors[b] = 2
                colors[c] = 3
            elif colors[a] == 2:
                colors[b] = 1
                colors[c] = 3
            else:
                colors[b] = 1
                colors[c] = 2
        elif colors[b] != 0:
            if colors[b] == 1:
                colors[a] = 2
                colors[c] = 3
            elif colors[b] == 2:
                colors[a] = 1
                colors[c] = 3
            else:
                colors[a] = 1
                colors[c] = 2
    print(' '.join(list(map(str, colors[1:]))))

main()


from collections import defaultdict
def main():
    (n, m) = map(int, input().split(' '))
    colors = [0] * (n + 1)
    dances = []
    ma = defaultdict(int)
    for i in range(m):
        (a, b, c) = map(int, input().split(' '))
        if colors[a] > 0:
            colors[b] = 1 + colors[a] % 3
            colors[c] = 1 + (1 + colors[a] % 3) % 3
        elif colors[b] > 0:
            colors[a] = 1 + colors[b] % 3
            colors[c] = 1 + (1 + colors[b] % 3) % 3
        elif colors[c] > 0:
            colors[a] = 1 + colors[c] % 3
            colors[b] = 1 + (1 + colors[c] % 3) % 3
        else:
            colors[a] = 1
            colors[b] = 2
            colors[c] = 3
    print(' '.join(list(map(str, colors[1:]))))

main()


import sys
def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

n,m = rinput()
A = []
for _ in range(m):
    A.append(rlinput())
ans = [0]*(n+1)
for i in range(m):
    array = [ans[A[i][0]],ans[A[i][1]],ans[A[i][2]]]
    if array.count(0) == 3:
        ans[A[i][0]] = 1
        ans[A[i][1]] = 2
        ans[A[i][2]] = 3
    else:
        for j in range(3):
            if array[j] != 0:
                break
        p = set([1,2,3]) - set([array[j]])
        p = list(p)
        index = 0
        for k in range(3):
            if array[k] == 0:
                ans[A[i][k]] = p[index]
                index += 1
print(*ans[1:])


n,m=map(int,input().split(" "))
cl=[0]*(n+1)
for i in range(m):
    x,y,z=list(map(int,input().split(" ")))
    if i==0 or (cl[x]==0 and cl[y]==0 and cl[z]==0):
        cl[x]=1
        cl[y]=2
        cl[z]=3
    else:
        if cl[x]!=0:
            if cl[x]==1:
                cl[y],cl[z]=2,3
            elif cl[x]==2:
                cl[y],cl[z]=1,3
            else:
                cl[y],cl[z]=1,2
        elif cl[y]!=0:
            if cl[y]==1:
                cl[x],cl[z]=2,3
            elif cl[y]==2:
                cl[x],cl[z]=1,3
            else:
                cl[x],cl[z]=1,2
        elif cl[z]!=0:
            if cl[z]==1:
                cl[y],cl[x]=2,3
            elif cl[z]==2:
                cl[y],cl[x]=1,3
            else:
                cl[y],cl[x]=1,2
cl = [str(i) for i in cl]
print(" ".join(cl[1:]))


from collections import defaultdict
n,m=map(int,input().split())
k=defaultdict(lambda :0)
for _ in range(m):
    t=[3,2,1]
    people= list(map(int, input().split()))
    ans=[]
    for i in people:
        if i in k:
            t.remove(k[i])
            people.remove(i)

    for i in people:
        k[i]=t.pop()
for i in sorted(k.keys()):
    print(k[i],end=" ")


def zip_sorted(a,b):

	# sorted  by a
	a,b = zip(*sorted(zip(a,b)))
	# sorted by b
	sorted(zip(a, b), key=lambda x: x[1])

	return a,b

import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
S = lambda : list(map(str,input().split()))

n,m=I()
w = [0]*m
r = [0]*m
b = [0]*m
w1 = [0]*(n+1)
for i in range(m):
	w[i],r[i],b[i] = I()
	if w1[w[i]]==0:
		for j in range(1,4):
			if w1[w[i]]==j or w1[r[i]]==j or w1[b[i]]==j:
				pass
			else:
				w1[w[i]] = j
				break
	if w1[r[i]]==0:
		for j in range(1,4):
			if w1[w[i]]==j or w1[r[i]]==j or w1[b[i]]==j:
				pass
			else:
				w1[r[i]] = j
				break
	if w1[b[i]]==0:
		for j in range(1,4):
			if w1[w[i]]==j or w1[r[i]]==j or w1[b[i]]==j:
				pass
			else:
				w1[b[i]] = j
				break
print(*w1[1:])


num_dancers,num_dances=map(int,input().split())
dance=list()
colors=[-1]*num_dancers
for i in range(0,num_dances):
    dance=(list(map(int,input().split())))
    col=[1,2,3]
    for j in dance:
        if colors[j-1] != -1:
            col.remove(colors[j-1])
    for j in dance:
        if colors[j-1] == -1:
            colors[j-1]=col.pop()
print(*colors,sep=' ')


num_dancers,num_dances=map(int,input().split())
dance=list()
for i in range(0,num_dances):
    dance.append(list(map(int,input().split())))
visited=[]
colors=[1]*num_dancers
for i in dance:
    col=[1,2,3]
    for j in i:
        if j in visited:
            col.remove(colors[j-1])
            continue
    for j in i:
        if j not in visited:
            visited.append(j)
            colors[j-1]=col[0]
            del col[0]
print(*colors,sep=' ')


num_dancers,num_dances=map(int,input().split())
dance=list()
visited=[]
colors=[1]*num_dancers
for i in range(0,num_dances):
    dance=(list(map(int,input().split())))
    col=[1,2,3]
    for j in dance:
        if j in visited:
            col.remove(colors[j-1])
    for j in dance:
        if j not in visited:
            visited.append(j)
            colors[j-1]=col.pop()
print(*colors,sep=' ')


num_dancers,num_dances=map(int,input().split())
dance=list()
for i in range(0,num_dances):
    dance.append(list(map(int,input().split())))
visited=[]
colors=[1]*num_dancers
for i in dance:
    col=[1,2,3]
    for j in i:
        if j in visited:
            col.remove(colors[j-1])
            continue
        visited.append(j)
        colors[j-1]=col[0]
        del col[0]
print(*colors,sep=' ')


#-------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():
    return map(int,input().split())
def array():
    return [int(i) for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

n,m=value()
dance=[]
color=defaultdict(int)
for i in range(m):
    a,b,c=value()
    dance.append((a,b,c))
color[dance[0][0]]=1
color[dance[0][1]]=2
color[dance[0][2]]=3
for i in dance[1:]:
    f=0
    for j in i:
        if(color[j]!=0):
            f=1
            com=j
            break
    if(f==0):
        color[i[0]]=1
        color[i[1]]=2
        color[i[2]]=3
    else:
        col=color[com]-1
        for j in i:
            if(j!=com):
                col=(col+1)%3
                color[j]=col+1
for i in range(1,n+1):
    print(color[i],end=" ")


n,m=map(int,input().split())
a=[0]*n
for i in range(m):
    s=list(map(int,input().split()))
    for j in range(1,4):
        if(a[s[j-1]-1]==0):
            a[s[j-1]-1]=j
        else:
            a[s[a[s[j-1]-1]-1]-1]=j
print(' '.join(map(str,a)))


import sys

inf = float("inf")
# sys.setrecursionlimit(10000000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]

# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n,m = get_ints()
mydict = dict()
ans = [0]*n
mydict2 = {1:[2,3],2:[1,3],3:[1,2]}
for i in range(m):
    a,b,c = get_ints()
    if a in mydict:
        x = mydict[a]
        ans[b-1] = mydict2[x][0]
        ans[c-1] = mydict2[x][1]
        mydict[b] = ans[b-1]
        mydict[c] = ans[c-1]
    elif b in mydict:
        x = mydict[b]
        ans[a - 1] = mydict2[x][0]
        ans[c - 1] = mydict2[x][1]
        mydict[a] = ans[a - 1]
        mydict[c] = ans[c - 1]
    elif c in mydict:
        x = mydict[c]
        ans[b - 1] = mydict2[x][0]
        ans[a - 1] = mydict2[x][1]
        mydict[b] = ans[b - 1]
        mydict[a] = ans[a - 1]
    else:
        ans[a-1],mydict[a] = 1,1
        ans[b-1],mydict[b] = 2,2
        ans[c-1],mydict[c] = 3,3
print(*ans)


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]

n, m = sp()
answer = l1d(n, 1)
occur = set()
for i in range(m):
    a, b, c = sp()
    if i == 0:
        answer[b-1] = 2
        answer[c-1] = 3
    else:
        if a in occur and b in occur and c in occur:
            temp = "do nothing"
        elif a in occur and b in occur:
            answer[c-1] = 6-(answer[a-1]+answer[b-1])
        elif a in occur and c in occur:
            answer[b-1] = 6-(answer[a-1]+answer[c-1])
        elif b in occur and c in occur:
            answer[a-1] = 6-(answer[b-1]+answer[c-1])
        elif a in occur:
            answer[b-1] = (answer[a-1] % 3) + 1
            answer[c-1] = 6-(answer[b-1]+answer[a-1])
        elif b in occur:
            answer[a-1] = (answer[b-1] % 3) + 1
            answer[c-1] = 6 - (answer[b-1] + answer[a-1])
        elif c in occur:
            answer[b-1] = (answer[c-1] % 3) + 1
            answer[a-1] = 6 - (answer[b-1] + answer[c-1])
        else:
            answer[b-1] = 2
            answer[c-1] = 3
        occur.add(a)
        occur.add(b)
        occur.add(c)
print(*answer)


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]

n, m = sp()
answer = l1d(n, 1)
occur = set()
for i in range(m):
    a, b, c = sp()
    if i == 0:
        answer[b-1] = 2
        answer[c-1] = 3
    else:
        if a in occur and b in occur and c in occur:
            temp = "do nothing"
        elif a in occur and b in occur:
            answer[c-1] = 6-(answer[a-1]+answer[b-1])
        elif a in occur and c in occur:
            answer[b-1] = 6-(answer[a-1]+answer[c-1])
        elif b in occur and c in occur:
            answer[a-1] = 6-(answer[b-1]+answer[c-1])
        elif a in occur:
            answer[b-1] = (answer[a-1] % 3) + 1
            answer[c-1] = 6-(answer[b-1]+answer[a-1])
        elif b in occur:
            answer[a-1] = (answer[b-1] % 3) + 1
            answer[c-1] = 6 - (answer[b-1] + answer[a-1])
        elif c in occur:
            answer[b-1] = (answer[c-1] % 3) + 1
            answer[a-1] = 6 - (answer[b-1] + answer[c-1])
        else:
            answer[b-1] = 2
            answer[c-1] = 3
    occur.add(a)
    occur.add(b)
    occur.add(c)
print(*answer)


import sys,math
from collections import deque
#input = sys.stdin.buffer.readline

def solve():
	n,m = map(int,input().split())
	dances = []
	edge = [[] for _ in range(n)]
	for i in range(m):
		a,b,c = map(int,input().split())
		dances.append([a-1,b-1,c-1])

		edge[a-1].append(i)
		edge[b-1].append(i)
		edge[c-1].append(i)

	visited = [False]*n
	poss = [[1,2,3] for i in range(n)]
	assign = [-1]*n

	i = 0
	q1 = deque()
	q2 = deque()
	while i<n:
		u=-1
		if len(q1)==0:
			if len(q2)==0:
				u=i
				i+=1
			else:
				u = q2.pop()
		else:
			u = q1.pop()

		if visited[u]:
			continue

		visited[u] = True
		assign[u] = poss[u][0]
		#print(u,assign[u])
		for jj in range(len(edge[u])):
			j = edge[u][jj]
			for k in range(3):
				if visited[dances[j][k]]==False:
					if assign[u] in poss[dances[j][k]]:
						poss[dances[j][k]].remove(assign[u])
					if len(poss[dances[j][k]])==2:
						q2.append(dances[j][k])
					else:
						q1.append(dances[j][k])

	for i in assign:
		print(i,end=" ")
	return;

#for _ in range(int(input())):
solve()


import sys,math
from collections import deque
#input = sys.stdin.buffer.readline

def solve():
	n,m = map(int,input().split())
	dances = []
	edge = [[] for _ in range(n)]
	for i in range(m):
		a,b,c = map(int,input().split())
		dances.append([a-1,b-1,c-1])

		edge[a-1].append(i)
		edge[b-1].append(i)
		edge[c-1].append(i)

	visited = [False]*n
	poss = [[1,2,3] for i in range(n)]
	assign = [-1]*n

	i = 0
	q1 = deque()
	q2 = deque()
	while i<n:
		u=-1
		if len(q1)==0:
			if len(q2)==0:
				u=i
				i+=1
			else:
				u = q2.pop()
		else:
			u = q1.pop()

		if visited[u]:
			continue

		visited[u] = True
		assign[u] = poss[u][0]
		print(u,assign[u])
		for jj in range(len(edge[u])):
			j = edge[u][jj]
			for k in range(3):
				if visited[dances[j][k]]==False:
					if assign[u] in poss[dances[j][k]]:
						poss[dances[j][k]].remove(assign[u])
					if len(poss[dances[j][k]])==2:
						q2.append(dances[j][k])
					else:
						q1.append(dances[j][k])

	for i in assign:
		print(i,end=" ")
	return;

#for _ in range(int(input())):
solve()


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = 'x' in file.mode or 'w' in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b'\n') + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

def solve():
    n, m = map(int, input().split())

    dncs = []
    for _ in range(m):
        a, b, c = map(int, input().split())
        dncs.append((a, b, c))

    res = [0] * (n + 1)

    for i in range(len(dncs)):
        a, b, c = dncs[i]
        c_taken = [1, 2, 3]
        n_taken = {1: False, 2: False, 3: False}
        if res[a] != 0:
            c_taken.remove(res[a])
            n_taken[1] = True
        if res[b] != 0:
            c_taken.remove(res[b])
            n_taken[2] = True
        if res[c] != 0:
            c_taken.remove(res[c])
            n_taken[3] = True

        # print(a, b, c, c_taken)

        if not n_taken[1]:
            res[a] = c_taken.pop(0)
        if not n_taken[2]:
            res[b] = c_taken.pop(0)
        if not n_taken[3]:
            res[c] = c_taken.pop(0)

    cout<<" ".join(map(str, res[1:]))<<endl

def main():
    solve()

if __name__ == "__main__":
    main()


from sys import stdin,stdout
from math import gcd
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n, m = iia()
arr = []
for _ in range(m):
    arr.append(iia())
col = [0] * (n)
for i in arr:
    cur = set([1,2,3])
    for j in i:
        if col[j - 1] > 0:
            cur.remove(col[j - 1])
    for j in i:
        if col[j - 1] == 0:
            col[j - 1] = cur.pop()
print(*col)


n,m=map(int,input().split())
a=[]
d={}
for i in range(m):
    a.append(list(map(int,input().split())))
for i in range(m):
    ex=n+1
    f=n+1
    for j in range(3):
        if a[i][j] in d:
            ex=a[i][j]
            f=d[a[i][j]]
            break
    t=1
    #print("ex "+str(ex)+str(a[i][j]))
    for j in range(3):
        if ex==a[i][j]:
            continue
        if t==f:
            t=(t+1)%4
        d[a[i][j]]=t
        t=(t+1)%4
#print(d)
for i in range(0,n):
    print(d[i+1],end=" ")


n,m=map(int,input().split())

ans=[-1]*(n+1)

for _ in range(m):

	dancers=list(map(int,input().split()))

	need=[1,2,3]

	for i in dancers:
		if(ans[i]!=-1):
			need.remove(ans[i])

	for i in dancers:
		if(ans[i]==-1):
			ans[i]=need.pop(-1)

print(*ans[1:])


import sys
sys.setrecursionlimit(10000)
n,m= [int(x) for x in input().strip().split()]

s = []
for i in range(m):
	a,b,c= [int(x) for x in input().strip().split()]
	s.append([a,b,c])
c = [0]*(n+2)
alpha = [1,2,3]
for i in range(m):
	alpha = [1,2,3]
	k = s[i]
	index=-1
	for j in range(3):
		if c[k[j]]!=0:
			index = j
			break
	if index!=-1:
		alpha.pop(c[k[index]]-1)
	for j in range(3):
		if j!=index :
			c[k[j]]=alpha.pop(0)

print(" ".join([str(x) for x in c[1:-1]]))


n, m = list(map(int, input().split()))
met = {}
for _ in range(m):
    arr = list(map(int, input().split()))
    if _ == 0:
        met[arr[0]] = 1
        met[arr[1]] = 2
        met[arr[2]] = 3
    else:
        arr2 = [1, 2, 3]
        xxx = 0
        for k in range(3):
            if arr[k] in met:
                arr2.remove(met[arr[k]])
            else:
                met[arr[k]] = arr2[xxx]
                xxx += 1
for kkk in range(1, n+1):
    print(met[kkk], end=' ')


n, m = list(map(int, input().split()))
met = {}
for _ in range(m):
    arr = list(map(int, input().split()))
    if _ == 0:
        met[arr[0]] = 1
        met[arr[1]] = 2
        met[arr[2]] = 3
    else:
        arr2 = [1, 2, 3]
        xxx = 0
        for k in range(3):
            if arr[k] in met:
                arr2.remove(met[arr[k]])
        for k in range(3):
            if arr[k] not in met:
                met[arr[k]] = arr2[xxx]
                xxx += 1
for kkk in range(1, n+1):
    print(met[kkk], end=' ')


n, m = (int(x) for x in input().split())
# print(n, m)

available = [1, 2, 3]
colors = [0]*(n+1)
# print(colors)

for i in range(m):
    # print(f"{i+1} iteration")
    a, b, c = [int(x) for x in input().split()]
    if colors[a] != 0:
        available.remove(colors[a])
    if colors[b] != 0:
        available.remove(colors[b])
    if colors[c] != 0:
        available.remove(colors[c])
    # print(f"available colors {available}")
    if len(available) > 0:
        if colors[a] == 0:
            colors[a] = available[0]
            available.remove(colors[a])
        if colors[b] == 0:
            colors[b] = available[0]
            available.remove(colors[b])
        if colors[c] == 0:
            colors[c] = available[0]
            available.remove(colors[c])

    available = [1, 2, 3]

for elt in colors[1:]:
    print(elt, end=" ")


n, m = (int(x) for x in input().split())
# print(n, m)

available = [1, 2, 3]
colors = [0]*(n+1)
# print(colors)

for i in range(3):
    # print(f"{i+1} iteration")
    a, b, c = [int(x) for x in input().split()]
    if colors[a] != 0:
        available.remove(colors[a])
    if colors[b] != 0:
        available.remove(colors[b])
    if colors[c] != 0:
        available.remove(colors[c])
    # print(f"available colors {available}")
    if len(available) > 0:
        if colors[a] == 0:
            colors[a] = available[0]
            available.remove(colors[a])
        if colors[b] == 0:
            colors[b] = available[0]
            available.remove(colors[b])
        if colors[c] == 0:
            colors[c] = available[0]
            available.remove(colors[c])

    available = [1, 2, 3]

for elt in colors[1:]:
    print(elt, end=" ")


dancers, dances = map(int, input().split())
people = []
default = '1 2 3'
for x in range(dances):
    people.append(list(map(int, input().split())))

if dances * 3 == dancers:
    ans = []
    for x in range(dances):
        ans.append(1)
        ans.append(2)
        ans.append(3)
    ans.sort()
    print(*ans)
else:
    val1 = people[0][0]
    val2 = people[0][1]
    val3 = people[0][2]
    freq = {val1: 1, val2: 2, val3: 3}
    for x in range(1, dances):
        if people[x][0] in freq.keys():
            if freq[people[x][0]] == 1:
                freq[people[x][1]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][0]] == 2:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 2
        elif people[x][1] in freq.keys():
            if freq[people[x][1]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][1]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 2
        elif people[x][2] in freq.keys():
            if freq[people[x][2]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][1]] = 3
            elif freq[people[x][2]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 2
        else:
            freq[people[x][0]] = 1
            freq[people[x][1]] = 2
            freq[people[x][2]] = 3
    for x in range(dancers):
        print(freq[x + 1], end=' ')


dancers, dances = map(int, input().split())
people = []
default = '1 2 3'
two = '2'
three = '3'
for x in range(dances):
    people.append(map(int, input().split()))

if dances * 3 == dancers:
    ans = [default for x in range(dances)]
    print(*ans)
else:
    ans = [default]
    flag = False
    for x in range(dancers - 3):
        if not flag:
            ans.append('2')
        else:
            ans.append('3')
        flag = flag ^ True
    print(*ans)


dancers, dances = map(int, input().split())
people = []
default = '1 2 3'
for x in range(dances):
    people.append(list(map(int, input().split())))

if dances * 3 == dancers:
    ans = [default for x in range(dances)]
    print(*ans)
else:
    val1 = people[0][0]
    val2 = people[0][1]
    val3 = people[0][2]
    freq = {val1: 1, val2: 2, val3: 3}
    for x in range(1, dances):
        if people[x][0] in freq.keys():
            if freq[people[x][0]] == 1:
                freq[people[x][1]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][0]] == 2:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 2
            people[x][0] = ''
        elif people[x][1] in freq.keys():
            if freq[people[x][1]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][1]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 2
            people[x][1] = ''
        elif people[x][2] in freq.keys():
            if freq[people[x][2]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][1]] = 3
            elif freq[people[x][2]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 2
            people[x][2] = ''
    for x in range(0, dances):
        for z in range(3):
            if people[x][z] != '':
                people[x][z] = freq[people[x][z]]
    ans = []
    for x in people:
        for z in x:
            if z != '':
                ans.append(z)
    print(*ans)


dancers, dances = map(int, input().split())
people = []
default = '1 2 3'
for x in range(dances):
    people.append(list(map(int, input().split())))

if dances * 3 == dancers:
    ans = []
    for x in range(dances):
        ans.append(1)
        ans.append(2)
        ans.append(3)
    ans.sort()
    print(*ans)
else:
    val1 = people[0][0]
    val2 = people[0][1]
    val3 = people[0][2]
    freq = {val1: 1, val2: 2, val3: 3}
    for x in range(1, dances):
        if people[x][0] in freq.keys():
            if freq[people[x][0]] == 1:
                freq[people[x][1]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][0]] == 2:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][1]] = 1
                freq[people[x][2]] = 2
            people[x][0] = ''
        elif people[x][1] in freq.keys():
            if freq[people[x][1]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][2]] = 3
            elif freq[people[x][1]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][2]] = 2
            people[x][1] = ''
        elif people[x][2] in freq.keys():
            if freq[people[x][2]] == 1:
                freq[people[x][0]] = 2
                freq[people[x][1]] = 3
            elif freq[people[x][2]] == 2:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 3
            else:
                freq[people[x][0]] = 1
                freq[people[x][1]] = 2
            people[x][2] = ''
    for x in range(0, dances):
        for z in range(3):
            if people[x][z] != '':
                people[x][z] = freq[people[x][z]]
    ans = []
    for x in people:
        for z in x:
            if z != '':
                ans.append(z)
    print(*ans)


def main():
	n,m = map(int,input().split())
	a = [ 0 for i in range(n)]
	for _ in range(m):
		dp = []
		m,n,p = map(int,input().split())
		m,n,p=m-1,n-1,p-1
		for i in range(1,4):
			if a[m]!=i and a[n]!=i and a[p]!=i:
				dp.append(i)
		index = 0
		if a[m]==0:
			a[m]=dp[index]
			index+=1
		if a[n]==0:
			a[n]=dp[index]
			index+=1
		if a[p]==0:
			a[p]=dp[index]
			index+=1
	for x in a:
		print(x,end=' ')

main()


n, m = map(int, input().split())
dances = []
for i in range(m):
    dances.append(sorted([int(i) for i in input().split()]))
dancers = [0] * (n + 1)
for i in range(m):
    possible = [1, 2, 3]
    dance = dances[i]
    for dancer in dance:
        if (dancers[dancer] != 0):
            possible.remove(dancers[dancer])
    for dancer in dance:
        if (dancers[dancer] == 0):
            dancers[dancer] = possible.pop(0)

print (' '.join([str(i) for i in dancers[1:]]))


n, m = map(int, input().split())
dances = []
for i in range(m):
    dances.append(sorted([int(i) for i in input().split()]))
dances.sort()
dancers = [0] * (n + 1)

for i, dancer in enumerate(dances[0]):
    dancers[dancer] = i + 1

for i in range(1, m):
    possible = [1, 2, 3]
    dance = dances[i]
    for dancer in dance:
        if (dancers[dancer] != 0):
            possible.remove(dancers[dancer])
    for dancer in dance:
        if (dancers[dancer] == 0):
            dancers[dancer] = possible.pop(0)

print (' '.join([str(i) for i in dancers[1:]]))


n, m = map(int, input().split())
dances = []
colors = [0] * (n + 1)
for _ in range(m):
    temp1, temp2, temp3 = map(int, input().split())
    dances.append([temp1, temp2, temp3])
i = 0
while i < len(dances):
    check = ['w', 'r', 'b']
    for j in range(len(dances[i])):
        if colors[dances[i][j]] != 0:
            for k in range(len(check)):
                if check[k] == colors[dances[i][j]]:
                    check[k] = -1
                    break
        elif colors[dances[i][j]] == 0:
            for k in range(len(check)):
                if check[k] != -1:
                    colors[dances[i][j]] = check[k]
                    check[k] = -1
                    break
    i += 1

for i in range(1, len(colors)):
    if colors[i] == 'w':
        print(1, end=' ')
    elif colors[i] == 'r':
        print(2, end=' ')
    else:
        print(3, end=' ')


n, m = map(int, input().split())
dances = []
colors = [0] * (n + 1)
for _ in range(m):
    temp1, temp2, temp3 = map(int, input().split())
    dances.append([temp1, temp2, temp3])
i = 0
# print(dances)
while i < len(dances):
    check = ['w', 'r', 'b']
    for j in range(len(check)):
        if colors[dances[i][0]] == check[j]:
            check[j] = -1
            break
        elif colors[dances[i][1]] == check[j]:
            check[j] = -1
            break
        elif colors[dances[i][2]] == check[j]:
            check[j] = -1
            break
    for j in range(len(dances[i])):
        # print(dances[i][j])
        if colors[dances[i][j]] == 0:
            if check[0] != -1:
                colors[dances[i][j]] = check[0]
                check[0] = -1
            elif check[1] != -1:
                colors[dances[i][j]] = check[1]
                check[1] = -1
            else:
                colors[dances[i][j]] = check[2]
                check[2] = -1
    # print(check)
    i += 1

for i in range(1, len(colors)):
    if colors[i] == 'w':
        print(1, end=' ')
    elif colors[i] == 'r':
        print(2, end=' ')
    else:
        print(3, end=' ')


n,m=map(int,input().split())
d={}
for i in range(m):
    x,y,z=list(map(int,input().split()))
    if i==0:
        d[x]=1
        d[y]=2
        d[z]=3
    else:
        if x in d:
            t1=d[x]
            if t1==1:
                d[y]=2
                d[z]=3
            elif t1==2:
                d[y]=1
                d[z]=3
            elif t1==3:
                d[y]=1
                d[z]=2
        elif y in d:
            t1=d[y]
            if t1==1:
                d[x]=2
                d[z]=3
            elif t1==2:
                d[x]=1
                d[z]=3
            elif t1==3:
                d[x]=1
                d[z]=2
        elif z in d:
            t1=d[z]
            if t1==1:
                d[y]=2
                d[x]=3
            elif t1==2:
                d[y]=1
                d[x]=3
            elif t1==3:
                d[y]=1
                d[x]=2
        else:
            d[x]=1
            d[y]=2
            d[z]=3
for i in range(n):
    print(d[i+1],end=" ")


n,m=list(map(int,input().split()))
count=[0]*(n+1)
flag=0
for ii in range(m):
    if ii==0:
        a=list(map(int,input().rstrip().split()))
        prev1=a[0]
        prev2=a[1]
        prev3=a[2]
        count[a[0]],count[a[1]],count[a[2]]=1,2,3
    else:
        a=list(map(int,input().rstrip().split()))
        toassign=[a[0],a[1],a[2]]
        avail=[1,2,3]
        if count[a[0]]>0:
            avail.pop(avail.index(count[a[0]]))
            toassign.pop(toassign.index(a[0]))
        if count[a[1]]>0:
            avail.pop(avail.index(count[a[1]]))
            toassign.pop(toassign.index(a[1]))

        if count[a[2]]>0:
            avail.pop(avail.index(count[a[2]]))
            toassign.pop(toassign.index(a[2]))
        l=0

        for i in toassign:
            count[i]=avail[l]
            l+=1
count.pop(0)
print(*count)


n,m=list(map(int,input().split()))
count=[0]*(n+1)
flag=0
for kk in range(m):
    if kk==0:

        a,b,c=list(map(int,input().split()))
        count[a]=1
        count[b]=2
        count[c]=3
        prev1=a
        prev2=b

        prev3=c
    else:
        a=list(map(int,input().rstrip().split()))
        flag=0

        for i in range(3):
            if a[i]==prev1:
                flag=1
                count[a[i]]=count[prev1]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev1]))
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                break
            if a[i]==prev2:
                flag=1
                count[a[i]]=count[prev2]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev2]))
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                break
            if a[i]==prev3:
                flag=1
                count[a[i]]=count[prev3]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev3]))
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                break
        if flag==1:
            pass
        else:
            count[a[0]]=1
            count[a[1]]=2
            count[a[2]]=3
count.pop(0)
print(*count)


n,m=list(map(int,input().split()))
count=[0]*(n+1)
flag=0
for kk in range(m):
    if kk==0:

        a,b,c=list(map(int,input().split()))
        count[a]=1
        count[b]=2
        count[c]=3
        prev1=a
        prev2=b

        prev3=c
    else:
        a=list(map(int,input().rstrip().split()))
        flag=0
        #print(prev1,prev2,prev3)
        for i in range(3):
            if a[i]==prev1:

                flag=1
                count[a[i]]=count[prev1]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev1]))
                #print(ans)
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                prev1=a[0]
                prev2=a[1]
                prev3=a[2]
                break
            if a[i]==prev2:

                flag=1
                count[a[i]]=count[prev2]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev2]))
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                prev1=a[0]
                prev3=a[2]
                prev2=a[1]
                break
            if a[i]==prev3:

                flag=1
                count[a[i]]=count[prev3]
                ans=[1,2,3]
                ans.pop(ans.index(count[prev3]))
                l=0
                for j in range(3):
                    if i==j:
                        pass
                    else:
                        count[a[j]]=ans[l]
                        l+=1
                prev1=a[0]
                prev2=a[1]
                prev3=a[2]
                break

        if flag==1:
            pass
        else:
            count[a[0]]=1
            count[a[1]]=2
            count[a[2]]=3
count.pop(0)
print(*count)


#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1005, K = 1e6+7, M = 998244353;

int a[K];
int n, m;
int l[N], r[N];

void zero() {
    cout<<0<<endl;
    exit(0);
}

void compress() {
    m = unique(a+1, a+m+1) - a-1;
//    for (int i=1; i<=m; i++)    cout<<a[i]<<" "; cout<<endl;

}

LL dp[N][N];
vector<int> pos[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m;

    for (int i=1; i<=m; i++)    cin>>a[i];
    compress();

    for (int i=1; i<=m; i++) {
        if (!l[a[i]])   l[a[i]] = i;
        r[a[i]] = i;
        pos[a[i]].push_back(i);
    }

    if (m>=2*n) zero();

    for (int i=1; i<=m; i++) {
        dp[i][i-1] = 1;
    }
    dp[m+1][m] = 1;

    for (int len = 1; len <= m; len++) {
        for (int L=1; L+len-1<=m; L++) {
            int R = L+len-1;

            int v = K;
            for (int i=L; i<=R; i++)
                if (a[i] < v) {
                    v = a[i];
                }

            if (!(L <= l[v] && r[v] <= R))  continue;

            LL left = 0, right = 0;

            for (int rr = r[v]; rr<=R; rr++)
                if (a[rr] < v)  continue;
                else right = (right + dp[r[v]+1][rr]*dp[rr+1][R])%M;

            for (int ll = l[v]; ll>=L; ll--)
                if (a[ll] < v)  continue;
                else left = (left + dp[L][ll-1]*dp[ll][l[v]-1])%M;

            dp[L][R] = (left*right)%M;

            for (int i=1; i<pos[v].size(); i++)
                dp[L][R] = (dp[L][R]*dp[pos[v][i-1]+1][pos[v][i]-1])%M;

//            cout<<"---> "<<L<<" "<<R<<" "<<v<<" "<<l[v]<<" "<<r[v]<<": "<<dp[L][R]<<endl;
        }
    }
    cout<<dp[1][m]<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1005, K = 1e6+7, M = 998244353;

PII tr[4*K];
int lz[4*K];

PII combine (PII left, PII right) {
    return PII(min(left.first, right.first), max(left.second, right.second));
}

///2. Push lazy down and merge lazy
void propagate(int u, int st, int en) {
    if (lz[u] == -1)        return;
    tr[u] = PII(lz[u], lz[u]);
    if (st!=en) {
        lz[2*u] = lz[u];
        lz[2*u+1] = lz[u];
    }
    lz[u] = -1;
}

void build(int u, int st, int en) {
    if (st==en) {
        tr[u] = {0, 0};
        lz[u] = -1;
    }
    else {
        int mid = (st+en)/2;
        build(2*u, st, mid);
        build(2*u+1, mid+1, en);
        tr[u] = combine(tr[2*u], tr[2*u+1]);
        lz[u] = -1;              ///3. Initialize
    }
}

void update(int u, int st, int en, int l, int r, int x) {
    propagate(u, st, en);
    if (r<st || en<l)  return;
    else if (l<=st && en<=r) {
        lz[u] = x;
        propagate(u, st, en);
    }
    else {
        int mid = (st+en)/2;
        update(2*u, st, mid, l, r, x);
        update(2*u+1, mid+1, en, l, r, x);
        tr[u] = combine(tr[2*u], tr[2*u+1]);
    }
}

PII query(int u, int st, int en, int l, int r) {
    propagate(u, st, en);
    if (r<st || en<l)  return PII(N, -N);        /// 5. Proper null value
    else if (l<=st && en<=r)    return tr[u];
    else {
        int mid = (st+en)/2;
        return combine(query(2*u, st, mid, l, r), query(2*u+1, mid+1, en, l, r));
    }
}

int a[K];
int n, m;
int l[N], r[N];

void zero() {
    cout<<0<<endl;
    exit(0);
}

void compress() {
    m = unique(a+1, a+m+1) - a-1;
//    for (int i=1; i<=m; i++)    cout<<a[i]<<" "; cout<<endl;

}

LL dp[N][N];
vector<int> pos[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m;

    for (int i=1; i<=m; i++)    cin>>a[i];
    compress();

    for (int i=1; i<=m; i++) {
        if (!l[a[i]])   l[a[i]] = i;
        r[a[i]] = i;
        pos[a[i]].push_back(i);
    }

    build(1,1,m);
    for (int i=1; i<=n; i++) {
        PII pr = query(1,1,m,l[i],r[i]);
        if (pr.first != pr.second)  zero();
        int par = pr.first;
        update(1,1,m,l[i],r[i],i);
    }

    if (m>=2*n) zero();

    for (int i=1; i<=m; i++) {
        dp[i][i-1] = 1;
    }
    dp[m+1][m] = 1;

    for (int len = 1; len <= m; len++) {
        for (int L=1; L+len-1<=m; L++) {
            int R = L+len-1;

            int v = K;
            for (int i=L; i<=R; i++)
                if (a[i] < v) {
                    v = a[i];
                }

            if (!(L <= l[v] && r[v] <= R))  continue;

            LL left = 0, right = 0;

            for (int rr = r[v]; rr<=R; rr++)
                if (a[rr] < v)  continue;
                else right = (right + dp[r[v]+1][rr]*dp[rr+1][R])%M;

            for (int ll = l[v]; ll>=L; ll--)
                if (a[ll] < v)  continue;
                else left = (left + dp[L][ll-1]*dp[ll][l[v]-1])%M;

            dp[L][R] = (left*right)%M;

            for (int i=1; i<pos[v].size(); i++)
                dp[L][R] = (dp[L][R]*dp[pos[v][i-1]+1][pos[v][i]-1])%M;

//            cout<<"---> "<<L<<" "<<R<<" "<<v<<" "<<l[v]<<" "<<r[v]<<": "<<dp[L][R]<<endl;
        }
    }
    cout<<dp[1][m]<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 1005, K = 1e6+7, M = 998244353;

int a[K];
int n, m;
int l[N], r[N];

LL dp[N][N];
vector<int> pos[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m;

    for (int i=1; i<=m; i++)    cin>>a[i];
    m = unique(a+1, a+m+1) - a-1;

    for (int i=1; i<=m; i++) {
        if (!l[a[i]])   l[a[i]] = i;
        r[a[i]] = i;
        pos[a[i]].push_back(i);
    }

    if (m>=2*n) {
        cout<<0<<endl;
        return 0;
    }

    for (int i=1; i<=m; i++) {
        dp[i][i-1] = 1;
    }
    dp[m+1][m] = 1;

    for (int len = 1; len <= m; len++) {
        for (int L=1; L+len-1<=m; L++) {
            int R = L+len-1;

            int v = K;
            for (int i=L; i<=R; i++)
                if (a[i] < v) {
                    v = a[i];
                }

            if (!(L <= l[v] && r[v] <= R))  continue;

            LL left = 0, right = 0;

            for (int rr = r[v]; rr<=R; rr++)
                if (a[rr] < v)  continue;
                else right = (right + dp[r[v]+1][rr]*dp[rr+1][R])%M;

            for (int ll = l[v]; ll>=L; ll--)
                if (a[ll] < v)  continue;
                else left = (left + dp[L][ll-1]*dp[ll][l[v]-1])%M;

            dp[L][R] = (left*right)%M;

            for (int i=1; i<pos[v].size(); i++)
                dp[L][R] = (dp[L][R]*dp[pos[v][i-1]+1][pos[v][i]-1])%M;

//            cout<<"---> "<<L<<" "<<R<<" "<<v<<" "<<l[v]<<" "<<r[v]<<": "<<dp[L][R]<<endl;
        }
    }
    cout<<dp[1][m]<<endl;

}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int MOD = 998244353;
int N, M;
vector<int> A;
int last_occ[505];
ll dp[1005][1005];

ll getdp(int a, int b)
{
    if (a >= b)
        return 1;
    if (dp[a][b] != -1)
        return dp[a][b];

    ll mid = 1;
    int x = a;
    for (int i = a + 1; i <= b; i++)
        if (A[x] > A[i])
            x = i;
    int y = x;
    for (int i = x + 1; i <= b; i++)
        if (A[i] == A[y])
        {
            mid = mid*getdp(y + 1, i - 1) % MOD;
            y = i;
        }

    vector<int> good_left;
    good_left.push_back(a - 1);
    set<int> st_left;
    for (int i = a; i < x; i++)
    {
        st_left.insert(A[i]);
        if (last_occ[A[i]] == i)
            st_left.erase(A[i]);
        if (st_left.empty())
            good_left.push_back(i);
    }
    ll left = 0;
    for (auto idx : good_left)
        left = (left + getdp(a, idx)*getdp(idx + 1, x - 1) % MOD) % MOD;

    vector<int> good_right;
    good_right.push_back(y + 1);
    set<int> st_right;
    for (int i = y + 1; i <= b; i++)
    {
        st_right.insert(A[i]);
        if (last_occ[A[i]] == i)
            st_right.erase(A[i]);
        if (st_right.empty())
            good_right.push_back(i + 1);
    }
    ll right = 0;
    for (auto idx : good_right)
        right = (right + getdp(y + 1, idx - 1)*getdp(idx, b) % MOD) % MOD;

    dp[a][b] = mid*(left*right % MOD) % MOD;
    return dp[a][b];
}

int main()
{
    scanf("%d %d", &N, &M);
    for (int i = 0, c; i < M; i++)
    {
        scanf("%d", &c);
        if (A.empty() || A.back() != c)
        {
            A.push_back(c);
            last_occ[c] = A.size() - 1;
        }
    }
    M = A.size();

    set<int> st;
    for (int i = 0; i < M; i++)
    {
        st.insert(A[i]);
        if (*(--st.end()) != A[i])
        {
            printf("0\n");
            return 0;
        }
        if (last_occ[A[i]] == i)
            st.erase(A[i]);
    }

    memset(dp, -1, sizeof(dp));
    printf("%lld\n", getdp(0, M - 1));

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int MOD = 998244353;
int N, M;
vector<int> A;
int last_occ[505];
ll dp[1005][1005];

ll getdp(int a, int b)
{
    if (a >= b)
        return 1;
    if (dp[a][b] != -1)
        return dp[a][b];

    ll mid = 1;
    int x = a;
    for (int i = a + 1; i <= b; i++)
        if (A[x] > A[i])
            x = i;
    int y = x;
    for (int i = x + 1; i <= b; i++)
        if (A[i] == A[y])
        {
            mid = mid*getdp(y + 1, i - 1) % MOD;
            y = i;
        }

    vector<int> good_left;
    good_left.push_back(a - 1);
    set<int> st_left;
    for (int i = a; i < x; i++)
    {
        st_left.insert(A[i]);
        if (last_occ[A[i]] == i)
            st_left.erase(A[i]);
        if (st_left.empty())
            good_left.push_back(i);
    }
    ll left = 0;
    for (auto idx : good_left)
        left = (left + getdp(a, idx)*getdp(idx + 1, x - 1) % MOD) % MOD;

    vector<int> good_right;
    good_right.push_back(b + 1);
    set<int> st_right;
    for (int i = b; i > y; i--)
    {
        st_right.insert(A[i]);
        if (last_occ[A[i]] == i)
            st_right.erase(A[i]);
        if (st_right.empty())
            good_right.push_back(i);
    }
    ll right = 0;
    for (auto idx : good_right)
        right = (right + getdp(y + 1, idx - 1)*getdp(idx, b) % MOD) % MOD;

    dp[a][b] = mid*(left*right % MOD) % MOD;
    return dp[a][b];
}

int main()
{
    scanf("%d %d", &N, &M);
    for (int i = 0, c; i < M; i++)
    {
        scanf("%d", &c);
        if (A.empty() || A.back() != c)
        {
            A.push_back(c);
            last_occ[c] = A.size() - 1;
        }
    }
    M = A.size();

    set<int> st;
    for (int i = 0; i < M; i++)
    {
        st.insert(A[i]);
        if (*(--st.end()) != A[i])
        {
            printf("0\n");
            return 0;
        }
        if (last_occ[A[i]] == i)
            st.erase(A[i]);
    }

    memset(dp, -1, sizeof(dp));
    printf("%lld\n", getdp(0, M - 1));

    return 0;
}


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 2e3 + 10;
const ll MX6 = 1e6 + 10;
const ll MOD = 998244353;
ll n, m, val, len = 1;
ll A[MXN], B[MX6], dp[MXN][MXN], Min[MXN][MXN];
vector<ll> Pos[MXN];
bool cont;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i ++) cin >> B[i];
    for(int i = 1; i <= m; i ++){
        ll j = i;
        while(j <= m && B[j] == B[i]) j ++;
        A[len] = B[i];
        i = j - 1, len ++;
    }
    m = len - 1;
    if(m > 2 * n + 2) return cout << 0, 0;
    for(int i = 0; i <= m + 1; i ++){
        for(int j = 0; j <= m + 1; j ++) dp[i][j] = 1;
    }
    for(int i = 1; i <= m; i ++) Pos[A[i]].push_back(i);
    for(int len = 1; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            Min[l][r] = l;
            for(int i = l; i <= r; i ++){
                if(A[i] < A[Min[l][r]]) Min[l][r] = i;
            }
        }
    }
    for(int i = 1; i <= m; i ++) dp[i][i] = (Pos[A[i]].size() == 1);
    for(int len = 2; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            val = dp[l][r] = cont = 0;
            for(int i = l; i <= r; i ++){
                if(Pos[A[i]][0] < l || Pos[A[i]][Pos[A[i]].size() - 1] > r) cont = 1;
            }
            if(cont) continue;
            ll rng = A[Min[l][r]], now = 1, sz = Pos[rng].size();
            for(int i = 0; i < sz - 1; i ++){
                now = (now * dp[Pos[rng][i] + 1][Pos[rng][i + 1] - 1]) % MOD;
            }
            for(int i = l; i <= Pos[rng][0]; i ++){
                val = (val + (dp[l][i - 1] * dp[i][Pos[rng][0] - 1] % MOD)) % MOD;
            }
            for(int i = Pos[rng][sz - 1]; i <= r; i ++){
                dp[l][r] = (dp[l][r] + (dp[Pos[rng][sz - 1] + 1][i] * dp[i + 1][r] % MOD)) % MOD;
            }
            dp[l][r] = (dp[l][r] * (val * now % MOD)) % MOD;
        }
    }
    cout << dp[1][m] << '\n';
    return 0;
}
/*!
    I CHOOSE TO HAVE FAITH,
    BECAUSE WITHOUT THAT,
    I HAVE NOTHING....
    ITS THE ONLY THING THAT'S KEEPING ME GOING.
*/
//! N.N


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 2e3 + 10;
const ll MX6 = 1e6 + 10;
const ll MOD = 998244353;
ll n, m, val, len = 1;
ll A[MX6], B[MX6], dp[MXN][MXN], Min[MXN][MXN];
vector<ll> Pos[MXN];
bool cont;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i ++) cin >> B[i];
    for(int i = 1; i <= m; i ++){
        ll j = i;
        while(j <= m && B[j] == B[i]) j ++;
        A[len] = B[i];
        i = j - 1, len ++;
    }
    m = len - 1;
    if(m > 2 * n + 2) return cout << 0, 0;
    for(int i = 0; i <= m + 1; i ++){
        for(int j = 0; j <= m + 1; j ++) dp[i][j] = 1;
    }
    for(int i = 1; i <= m; i ++) Pos[A[i]].push_back(i);
    for(int len = 1; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            Min[l][r] = l;
            for(int i = l; i <= r; i ++){
                if(A[i] < A[Min[l][r]]) Min[l][r] = i;
            }
        }
    }
    for(int i = 1; i <= m; i ++) dp[i][i] = (Pos[A[i]].size() == 1);
    for(int len = 2; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            val = dp[l][r] = cont = 0;
            for(int i = l; i <= r; i ++){
                if(Pos[A[i]][0] < l || Pos[A[i]][Pos[A[i]].size() - 1] > r) cont = 1;
            }
            if(cont) continue;
            ll rng = A[Min[l][r]], now = 1, sz = Pos[rng].size();
            for(int i = 0; i < sz - 1; i ++){
                now = (now * dp[Pos[rng][i] + 1][Pos[rng][i + 1] - 1]) % MOD;
            }
            for(int i = l; i <= Pos[rng][0]; i ++){
                val = (val + (dp[l][i - 1] * dp[i][Pos[rng][0] - 1] % MOD)) % MOD;
            }
            for(int i = Pos[rng][sz - 1]; i <= r; i ++){
                dp[l][r] = (dp[l][r] + (dp[Pos[rng][sz - 1] + 1][i] * dp[i + 1][r] % MOD)) % MOD;
            }
            dp[l][r] = (dp[l][r] * (val * now % MOD)) % MOD;
        }
    }
    cout << dp[1][m] << '\n';
    return 0;
}
/*!
    I CHOOSE TO HAVE FAITH,
    BECAUSE WITHOUT THAT,
    I HAVE NOTHING....
    ITS THE ONLY THING THAT'S KEEPING ME GOING.
*/
//! N.N


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 500 + 10;
const ll MX6 = 1e6 + 10;
const ll MOD = 998244353;
ll n, m, val, len = 1;
ll A[MXN], B[MX6], dp[MXN][MXN], Min[MXN][MXN];
vector<ll> Pos[MXN];
bool cont;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i ++) cin >> B[i];
    for(int i = 1; i <= m; i ++){
        ll j = i;
        while(j <= m && B[j] == B[i]) j ++;
        A[len] = B[i];
        i = j - 1, len ++;
    }
    m = len - 1;
    if(m > 2 * n + 2) return cout << 0, 0;
    for(int i = 0; i <= m + 1; i ++){
        for(int j = 0; j <= m + 1; j ++) dp[i][j] = 1;
    }
    for(int i = 1; i <= m; i ++) Pos[A[i]].push_back(i);
    for(int len = 1; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            Min[l][r] = l;
            for(int i = l; i <= r; i ++){
                if(A[i] < A[Min[l][r]]) Min[l][r] = i;
            }
        }
    }
    for(int i = 1; i <= m; i ++) dp[i][i] = (Pos[A[i]].size() == 1);
    for(int len = 2; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            val = dp[l][r] = cont = 0;
            for(int i = l; i <= r; i ++){
                if(Pos[A[i]][0] < l || Pos[A[i]][Pos[A[i]].size() - 1] > r) cont = 1;
            }
            if(cont) continue;
            ll rng = A[Min[l][r]], now = 1, sz = Pos[rng].size();
            for(int i = 0; i < sz - 1; i ++){
                now = (now * dp[Pos[rng][i] + 1][Pos[rng][i + 1] - 1]) % MOD;
            }
            for(int i = l; i <= Pos[rng][0]; i ++){
                val = (val + (dp[l][i - 1] * dp[i][Pos[rng][0] - 1] % MOD)) % MOD;
            }
            for(int i = Pos[rng][sz - 1]; i <= r; i ++){
                dp[l][r] = (dp[l][r] + (dp[Pos[rng][sz - 1] + 1][i] * dp[i + 1][r] % MOD)) % MOD;
            }
            dp[l][r] = (dp[l][r] * (val * now % MOD)) % MOD;
        }
    }
    cout << dp[1][m] << '\n';
    return 0;
}
/*!
    I CHOOSE TO HAVE FAITH,
    BECAUSE WITHOUT THAT,
    I HAVE NOTHING....
    ITS THE ONLY THING THAT'S KEEPING ME GOING.
*/
//! N.N


///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 500 + 10;
const ll MOD = 998244353;
ll n, m, val, len = 1;
ll A[MXN], B[MXN], dp[MXN][MXN], Min[MXN][MXN];
vector<ll> Pos[MXN];
bool cont;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i ++) cin >> B[i];
    for(int i = 1; i <= m; i ++){
        ll j = i;
        while(j <= m && B[j] == B[i]) j ++;
        A[len] = B[i];
        i = j - 1, len ++;
    }
    m = len - 1;
    if(m > 2 * n + 2) return cout << 0, 0;
    for(int i = 0; i <= m + 1; i ++){
        for(int j = 0; j <= m + 1; j ++) dp[i][j] = 1;
    }
    for(int i = 1; i <= m; i ++) Pos[A[i]].push_back(i);
    for(int len = 1; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            Min[l][r] = l;
            for(int i = l; i <= r; i ++){
                if(A[i] < A[Min[l][r]]) Min[l][r] = i;
            }
        }
    }
    for(int i = 1; i <= m; i ++) dp[i][i] = (Pos[A[i]].size() == 1);
    for(int len = 2; len <= m; len ++){
        for(int l = 1, r = len; r <= m; l ++, r ++){
            val = dp[l][r] = cont = 0;
            for(int i = l; i <= r; i ++){
                if(Pos[A[i]][0] < l || Pos[A[i]][Pos[A[i]].size() - 1] > r) cont = 1;
            }
            if(cont) continue;
            ll rng = A[Min[l][r]], now = 1, sz = Pos[rng].size();
            for(int i = 0; i < sz - 1; i ++){
                now = (now * dp[Pos[rng][i] + 1][Pos[rng][i + 1] - 1]) % MOD;
            }
            for(int i = l; i <= Pos[rng][0]; i ++){
                val = (val + (dp[l][i - 1] * dp[i][Pos[rng][0] - 1] % MOD)) % MOD;
            }
            for(int i = Pos[rng][sz - 1]; i <= r; i ++){
                dp[l][r] = (dp[l][r] + (dp[Pos[rng][sz - 1] + 1][i] * dp[i + 1][r] % MOD)) % MOD;
            }
            dp[l][r] = (dp[l][r] * (val * now % MOD)) % MOD;
        }
    }
    cout << dp[1][m] << '\n';
    return 0;
}
/*!
    I CHOOSE TO HAVE FAITH,
    BECAUSE WITHOUT THAT,
    I HAVE NOTHING....
    ITS THE ONLY THING THAT'S KEEPING ME GOING.
*/
//! N.N