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

namespace Contest_14
{
    class Program
    {
        static void A()
        {
            var t = Console.ReadLine().Split(' ');
            int n = int.Parse(t[0]);
            int m = int.Parse(t[1]);

            int x1 = int.MaxValue, x2 = int.MinValue, y1 = int.MaxValue, y2 = int.MinValue;
            List<string> a = new List<string>();
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                a.Add(s);
                for (int j = 0; j < m; j++)
                {
                    if (s[j] == '*')
                    {
                        if (x1 > i)
                            x1 = i;
                        if (x2 < i)
                            x2 = i;
                        if (y1 > j)
                            y1 = j;
                        if (y2 < j)
                            y2 = j;
                    }
                }
            }

            for (int i = x1; i <= x2; i++)
            {
                for (int j = y1; j <= y2; j++)
                {
                    Console.Write(a[i][j]);
                }
                Console.WriteLine();
            }
        }

        static void B()
        {
            var t = Console.ReadLine().Split(' ');
            int n = int.Parse(t[0]);
            int x = int.Parse(t[1]);

            int min = int.MaxValue;
            int max = int.MinValue;
            int[] a = new int[1001];
            for (int i = 0; i < n; i++)
            {
                t = Console.ReadLine().Split(' ');
                int k = int.Parse(t[0]);
                int l = int.Parse(t[1]);

                if (k > l)
                {
                    int q = k;
                    k = l;
                    l = q;
                }
                if (i == 0)
                {
                    min = k;
                    max = l;
                    continue;
                }
                if (k > min)
                {
                    min = k;
                }
                if (l < max)
                    max = l;
            }
            if (max < min)
            {
                Console.WriteLine(-1);
                return;
            }
            if ((x >= min) && (x <= max))
                Console.WriteLine(0);
            else
                Console.WriteLine(Math.Min(Math.Abs(min - x), Math.Abs(max - x)));
        }

        class Point : IComparer<Point>
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {
                this.x = x;
                this.y = y;
            }

            public int Compare(Point p1, Point p2)
            {
                if (p1.x != p2.x)
                    return p1.x.CompareTo(p2.x);
                else
                    return p1.y.CompareTo(p2.y);
            }

            public bool isGood (Point p)
            {
                if ((x == p.x) && (y != p.y))
                    return true;
                if ((y == p.y) && (x != p.x))
                    return true;
                return false;
            }

            public void deleteInList(List<Point> b)
            {
                for (int j = 0; j < b.Count; j++)
                {
                    Point temp = b[j];
                    if ((temp.x == this.x) && (temp.y == this.y))
                    {
                        b.RemoveAt(j);
                        break;
                    }
                }

            }

        }

        static void C()
        {
            List<int[]> a = new List<int[]>();

            for (int i = 0; i < 4; i++)
            {
                var t = Console.ReadLine().Split(' ');
                var t1 = new int[] { int.Parse(t[0]), int.Parse(t[1]), int.Parse(t[2]), int.Parse(t[3]) };
                for (int j = 0; j < a.Count; j++)
                {
                    var k = a[j];

                    if ((k[0] == t1[0]) && (k[1] == t1[1]) && (k[2] == t1[2]) && (k[3] == t1[3]))
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                    if ((k[2] == t1[0]) && (k[3] == t1[1]) && (k[0] == t1[2]) && (k[1] == t1[3]))
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
                a.Add(t1);

            }

            List<Point> b = new List<Point>();

            int xl = int.MaxValue, yl = int.MinValue, xr = int.MinValue, yr = int.MaxValue;

            for (int i = 0; i < 4; i++)
            {
                int[] t = a[i];
                Point l1 = new Point(t[0], t[1]);
                Point l2 = new Point(t[2], t[3]);
                b.Add(l1);
                b.Add(l2);
                if (t[0] < xl)
                    xl = t[0];
                if (t[1] > yl)
                    yl = t[1];
                if (t[2] > xr)
                    xr = t[2];
                if (t[3] < yr)
                    yr = t[3];
                if (!l1.isGood(l2))
                {
                    Console.WriteLine("NO");
                    return;
                }
            }

            Point p1 = new Point(xl, yl);
            Point p2 = new Point(xr, yr);

            for (int i = 0; i < 2; i++)
            {
                p1.deleteInList(b);
                p2.deleteInList(b);
                new Point(p1.x, p2.y).deleteInList(b);
                new Point(p2.x, p1.y).deleteInList(b);
            }
            if (b.Count > 0)
                Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }

        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"C:\1.txt"));
            C();
        }
    }
}


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

namespace Codeforce
{

    class Printer
    {
        StringBuilder sb;

        public Printer()
        {
            sb = new StringBuilder();
        }

        public void WriteLine(string s)
        {
            sb.AppendLine(s);
        }
        public void WriteLine()
        {
            sb.AppendLine();
        }
        public void Write(string s)
        {
            sb.Append(s);
        }

        public void Print()
        {
            Console.Write(sb);
        }
    }

    class Program
    {
        static StreamReader input = new StreamReader(Console.OpenStandardInput());
        //static StreamWriter output = new StreamWriter(Console.OpenStandardOutput());

        static int nextInt()
        {
            int t = input.Read();
            while ((t < '0' || t > '9') && t != '-') t = input.Read();
            int sign = 1;
            if (t == '-')
            {
                sign = -1;
                t = input.Read();
            }
            int x = 0;
            while (t >= '0' && t <= '9')
            {
                x *= 10;
                x += t - '0';
                t = input.Read();
            }
            return x * sign;
        }

        static int[] parseInt(string s)
        {
            string[] temp = s.Split(' ');
            int[] res = new int[temp.Length];
            for (int i = 0; i < temp.Length; i++)
            {
                res[i] = Convert.ToInt32(temp[i]);
            }
            return res;
        }

        static double Dist(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }
        struct Point
        {
            public double x { get; set; }
            public double y { get; set; }

            public Point(double _x, double _y)
                : this()
            {
                x = _x;
                y = _y;
            }
            public double DistTo(Point p2)
            {
                return Dist(x, y, p2.x, p2.y);
            }
        }

        class Segment
        {
            public Point first { get; set; }
            public Point last { get; set; }

            public Segment()
            {

            }
            public Segment(Point f, Point l)
            {
                first = f;
                last = l;
            }

            public void Swap()
            {
                Point tmp = first;
                first = last;
                last = tmp;
            }
        }
        static bool[] used = new bool[4];

        static bool isP(int i, Segment[] P, int length)
        {
            if (!(P[i].first.x == P[i].last.x || P[i].first.y == P[i].last.y) || length > 5)
                return false;
            if (length == 5 && i == 0)
                return true;

            int j = i + 1 < 4 ? i + 1 : 0;
            if ((!used[j] || j == 0) && P[i].last.x == P[j].first.x && P[i].last.y == P[j].first.y && (P[j].first.x == P[j].last.x || P[j].first.y == P[j].last.y))
            {
                used[j] = true;
                return isP(j, P, length + 1);
            }

            return false;
        }

        static void Main(string[] args)
        {
            Printer printer = new Printer();

            List<Segment> P = new List<Segment>();

            Segment[] S = new Segment[4];

            int xmin = int.MaxValue, xmax = int.MinValue, ymin = int.MaxValue, ymax = int.MinValue;
            Dictionary<string, int> D = new Dictionary<string, int>();
            for (int i = 0; i < 4; i++)
            {
                var tmp = parseInt(Console.ReadLine());

                xmin = Math.Min(xmin, tmp[0]);
                xmin = Math.Min(xmin, tmp[2]);
                xmax = Math.Max(xmax, tmp[0]);
                xmax = Math.Max(xmax, tmp[2]);

                ymin = Math.Min(ymin, tmp[1]);
                ymin = Math.Min(ymin, tmp[3]);
                ymax = Math.Max(ymax, tmp[1]);
                ymax = Math.Max(ymax, tmp[3]);

                string f = tmp[0].ToString() + " " + tmp[1].ToString();
                if (D.Keys.Contains(f))
                {
                    D[f]++;
                }
                else
                    D[f] = 1;
                f = tmp[2].ToString() + " " + tmp[3].ToString();
                if (D.Keys.Contains(f))
                {
                    D[f]++;
                }
                else
                    D[f] = 1;
                P.Add(new Segment(new Point(tmp[0], tmp[1]), new Point(tmp[2], tmp[3])));
            }

            foreach (var item in D)
            {
                if (item.Value != 2)
                {
                    Console.WriteLine("NO");
                    return;
                }
            }

            if (xmin == xmax || ymin == ymax || D.Count != 4)
            {
                Console.WriteLine("NO");
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                if ((P[i].first.x == xmin && P[i].first.y == ymax && P[i].last.x == xmax && P[i].last.y == ymax)
                 || (P[i].last.x == xmin && P[i].last.y == ymax && P[i].first.x == xmax && P[i].first.y == ymax))
                {
                    used[1] = true;
                }
                if ((P[i].first.x == xmin && P[i].first.y == ymin && P[i].last.x == xmin && P[i].last.y == ymax)
                 || (P[i].last.x == xmin && P[i].last.y == ymin && P[i].first.x == xmin && P[i].first.y == ymax))
                {
                    used[0] = true;
                }
                if ((P[i].first.x == xmin && P[i].first.y == ymin && P[i].last.x == xmax && P[i].last.y == ymin)
                 || (P[i].last.x == xmin && P[i].last.y == ymin && P[i].first.x == xmax && P[i].first.y == ymin))
                {
                    used[2] = true;
                }
                if ((P[i].first.x == xmax && P[i].first.y == ymin && P[i].last.x == xmin && P[i].last.y == ymin)
                 || (P[i].last.x == xmax && P[i].last.y == ymin && P[i].first.x == xmin && P[i].first.y == ymin))
                {
                    used[3] = true;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (!used[i])
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
            printer.Print();

        }
    }
}


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

namespace CodeForces
{
    class Program_R158_Div2_255A
    {
        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine().Split());
            long n = int.Parse(s[0]);
            long m = int.Parse(s[1]);

            long num = 1;
            for (int i = 0; i < n; i++)
                num = (num * 3);
            num = (num -1) % m;

            Console.WriteLine(num);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

class CF_227C
{
    public int solve(int n, int m)
    {
        int k = 1;
        for (int i = 0; i < n; i++)
        {
            k *= (3 % m); k %= m;
        }
        return k - 1;
    }

    public static void Main(string[] args)
    {
        string[] lines = Console.ReadLine().Split();
        int n = Convert.ToInt32(lines[0]);
        int m = Convert.ToInt32(lines[1]);
        Console.WriteLine(new CF_227C().solve(n, m));
    }
}

#if !ONLINE_JUDGE
namespace CodeForces
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class Test_CF_227C
    {
        [TestMethod]
        public void Test1()
        {
            Assert.AreEqual(2, new CF_227C().solve(1, 10));
        }

        [TestMethod]
        public void Test2()
        {
            Assert.AreEqual(2, new CF_227C().solve(3, 8));
        }
    }
}
#endif


using System;
using System.Collections.Generic;
using System.Text;

class CF_227C
{
    public int solve(int n, int m)
    {
        int k = 1;
        int power = 3 % m;
        for (int i = 0; i < n; i++)
        {
            k = (k * power) % m;
        }
        return k - 1;
    }

    public static void Main(string[] args)
    {
        string[] lines = Console.ReadLine().Split();
        int n = Convert.ToInt32(lines[0]);
        int m = Convert.ToInt32(lines[1]);
        Console.WriteLine(new CF_227C().solve(n, m));
    }
}

#if !ONLINE_JUDGE
namespace CodeForces
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class Test_CF_227C
    {
        [TestMethod]
        public void Test1()
        {
            Assert.AreEqual(2, new CF_227C().solve(1, 10));
        }

        [TestMethod]
        public void Test2()
        {
            Assert.AreEqual(2, new CF_227C().solve(3, 8));
        }
    }
}
#endif


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, m, r=1;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt32(inp[0]);
            m = Convert.ToInt32(inp[1]);

            for (int i = 1; i <= n; i++)
            {
                r = (r * 3) % m;
            }

            Console.WriteLine((r-1)%m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

class CF_227C
{
    public long[] powersOf3 = new long[]
    {
          3
        , 9
        , 27
        , 81
        , 243
        , 729
        , 2187
        , 6561
        , 19683
        , 59049
        , 177147
        , 531441
        , 1594323
        , 4782969
        , 14348907
        , 43046721
        , 129140163
        , 387420489
        , 1162261467
        , 3486784401
        , 10460353203
        , 31381059609
        , 94143178827
    };

    public long solve(long n, long m)
    {
        long k = 1;
        long left = n;
        while (left > 0)
        {
            long power = (n % powersOf3.Length);
            k *= (powersOf3[power - 1] % m); k %= m;
            left -= power;
        }
        return k - 1;
    }

    public static void Main(string[] args)
    {
        string[] lines = Console.ReadLine().Split();
        long n = Convert.ToInt64(lines[0]);
        long m = Convert.ToInt64(lines[1]);
        Console.WriteLine(new CF_227C().solve(n, m));
    }
}

#if !ONLINE_JUDGE
namespace CodeForces
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class Test_CF_227C
    {
        [TestMethod]
        public void Test1()
        {
            Assert.AreEqual(2, new CF_227C().solve(1, 10));
        }

        [TestMethod]
        public void Test2()
        {
            Assert.AreEqual(2, new CF_227C().solve(3, 8));
        }
    }
}
#endif


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static Int64 powermod(Int64 b, Int64 n, Int64 m)
        {
            Int64 result = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                n = n / 2;
            }
            return (result - 1) % m;
        }

        static void Main(string[] args)
        {
            Int64 n, m;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt64(inp[0]);
            m = Convert.ToInt64(inp[1]);

            Console.WriteLine(powermod(3, n, m));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

public class taskA
{
    static void Main(string[] args)
    {
        string inp = Console.ReadLine();
        string[] spl = inp.Split(' ');
        int n, m;
        n = int.Parse(spl[0]);
        m = int.Parse(spl[1]);

        long res = 1;
        while (n > 0)
        {
            if ((n % 2) == 0)
            {
                res *= res;
                n /= 2;
            }
            else
            {
                res *= 3;
                n--;
            }
            res = res % m;
        }
        res = (res - (long)1+(long)m) % m;
        Console.WriteLine(res);

    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static int powermod(int b, int n, int m)
        {
            Int64 result = 1;
            while (n > 0)
            {
                if ((n % 2) == 1)
                {
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                n = n / 2;
            }
            return (int)(result - 1) % m;
        }

        static void Main(string[] args)
        {
            int n, m;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt32(inp[0]);
            m = Convert.ToInt32(inp[1]);

            Console.WriteLine(powermod(3, n, m));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static Int64 powermod(Int64 b, Int64 n, Int64 m)
        {
            Int64 result = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                n = n / 2;
            }
            return (result - 1) % m;
        }

        static void Main(string[] args)
        {
            Int64 n, m;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt32(inp[0]);
            m = Convert.ToInt32(inp[1]);

            Console.WriteLine(powermod(3, n, m));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

namespace CodeForces
{

	class A
	{

		private void Solve()
		{
			int n = NextInt(), m = NextInt();
			Out.WriteLine( ( pow( 3, n, m ) - 1 + m ) % m );
		}

		int pow( int a, int b, int m )
		{
			if ( b == 1 ) return 1 % m;
			int r = pow( a, b / 2, m );
			r = (int)( ( (long)r * r ) % m );
			if ( b % 2 == 1 )
			{
				r = (int)( ( (long)r * a ) % m );
			}
			return r;
		}

		#region Local wireup

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, 20000000 );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new A().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace C24_09_12
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Regex.Split(Console.ReadLine(), " ");
            Int64 n = Int64.Parse(s[0]);
            Int64 m = Int64.Parse(s[1]);
            Int64 k = 1;
            Int64 t = 3;
            while (n > 0)
            {
                if( n%2==1) k *= t;
                n /= 2;
                t *= t;
                k %= m;
                t %= m;
            }
            if (m == 1)
                k = 0;
            else
                if (k == 0) k = m - 1;
                else k--;
            Console.WriteLine("{0}", 2%1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace C24_09_12
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Regex.Split(Console.ReadLine(), " ");
            Int64 n = Int64.Parse(s[0]);
            Int64 m = Int64.Parse(s[1]);
            Int64 k = 1;
            Int64 t = 3;
            while (n > 0)
            {
                if( n%2==1) k *= t;
                n /= 2;
                t *= t;
                k %= m;
            }
            if (k == 0) k = m - 1;
            else k--;
            Console.WriteLine("{0}", k);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

class CF_227C
{
    public long solve(long n, long m)
    {
        long[] powerof3 = new long[32];
        long k = 1;
        long power = 3 % m;
        for (int i = 0; i < 32; i++)
        {
            k = (k * power) % m;
            powerof3[i] = k;
        }

        k = 1;
        for (int i = 0; i < 32; i++)
        {
            if ((n & (1 << i)) != 0)
            {
                k *= powerof3[i]; k %= m;
            }
        }
        return k - 1;
    }

    public static void Main(string[] args)
    {
        string[] lines = Console.ReadLine().Split();
        long n = Convert.ToInt64(lines[0]);
        long m = Convert.ToInt64(lines[1]);
        Console.WriteLine(new CF_227C().solve(n, m));
    }
}

#if !ONLINE_JUDGE
namespace CodeForces
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class Test_CF_227C
    {
        [TestMethod]
        public void Test1()
        {
            Assert.AreEqual(2, new CF_227C().solve(1, 10));
        }

        [TestMethod]
        public void Test2()
        {
            Assert.AreEqual(2, new CF_227C().solve(3, 8));
        }

        [TestMethod]
        public void Test3()
        {
            Assert.AreEqual(690359500, new CF_227C().solve(331358794, 820674098));
        }
    }
}
#endif


using System;
using System.Linq;
using System.Text;

namespace VKD
{
    class Program
    {
        static int m = 10;

        static long Pow(long a, int p)
        {
            if (p == 0)
            {
                return 1 % m;
            }

            if (p % 2 == 1)
            {
                return ((a % m) * Pow(a, p - 1) % m) % m;
            }
            else
            {
                var t = Pow(a, p / 2) % m;
                return (t * t) % m;
            }

        }
        static void Main(string[] args)
        {
            var inp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = inp[0];
            m = inp[1];

            long ans = 0;
            ans = (Pow(3, n) - 1 % m + m) % m;
            Console.WriteLine(ans);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static Int64 powermod(Int64 b, Int64 n, Int64 m)
        {
            Int64 result = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                n = n / 2;
            }
            return result;

            //return (result - 1) % m;
        }

        static void Main(string[] args)
        {
            Int64 n, m;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt64(inp[0]);
            m = Convert.ToInt64(inp[1]);

            Int64 r = powermod(3, n, m);
            r = r == 0 ? m - 1 : r-1;
            Console.WriteLine(r);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

public class taskA
{
    static void Main(string[] args)
    {
        string inp = Console.ReadLine();
        string[] spl = inp.Split(' ');
        int n, m;
        n = int.Parse(spl[0]);
        m = int.Parse(spl[1]);

        long res = pow(3,n,m);

        res = (res - (long)1+(long)m) % m;

        Console.WriteLine(res);

    }

    private static long pow(int p, int n, int m)
    {
        long res = 0;
        if (n == 0) return 1;

        if ((n % 2) == 0)
        {
            res = pow(p, n / 2, m);
            res = res * res;
            res %= m;

        }
        else
        {
            res = pow(p, n - 1, m);
            res = res * p;
            return res;
        }
        res %= m;
        return res;
    }

}


using System;
using System.Numerics;

public class CF_227C
{
    public CF_227C()
    {
    }

    public long solve(int n, int m)
    {
		long[] powersof3 = new long[32];
		powersof3[0] = 3 % m;
		for (int i = 1; i < 32; i++)
        {
			powersof3[i] = (powersof3[i - 1] * powersof3[i - 1]) % m;
		}

        long answer = 1;
        for (int i = 0; i < 32; i++)
        {
            if ((n & (1 << i)) != 0)
            {
                answer *= powersof3[i];
                answer %= m;
            }
        }
        answer = (answer == 0 ? m - 1 : answer - 1);
        return answer;
	}

    public static void Main(string[] args)
    {
        string[] lines = Console.ReadLine().Split();
        int n = Convert.ToInt32(lines[0]);
        int m = Convert.ToInt32(lines[1]);
        Console.WriteLine(new CF_227C().solve(n, m));
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static Int64 powermod(Int64 b, Int64 n, Int64 m)
        {
            Int64 result = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                n = n / 2;
            }
            return (m+result-1)%m;
        }

        static void Main(string[] args)
        {
            Int64 n, m;
            string[] inp = Console.ReadLine().ToString().Split(' ');
            n = Convert.ToInt64(inp[0]);
            m = Convert.ToInt64(inp[1]);
            Console.WriteLine(powermod(3, n, m));
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Flying_Saucer_Segments
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static int mod;

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

        private static void Main(string[] args)
        {
            int n = Next();
            mod = Next();

            long res = Pow(3, n) - 1;
            if (res < 0)
                res += mod;

            writer.WriteLine(res);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace CodeForces
{
    class Program_R158_Div2_255A
    {
        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine().Split());
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            long num = GetBigPowerMod(3, n, m);
            num--;
            if (num < 0) num = m - 1;
            Console.WriteLine(num);
        }

        static long GetBigPowerMod(long b, int n, int m)
        {
            //num will be b^n mod m; for n, m up to 1e10
            //long num = 1
            //for (int i = 0; i < n; i++)
            //    num = (num * b) % m;

            long num = 1;
            while (n > 0)
            {
                if (n % 2 == 1)
                    num = (num * b) % m;
                b = (b * b) % m;
                n /= 2;
                //Console.WriteLine("{0} {1} {2}", num, b, n);
            }
            return num;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Codeforces
{
    class C
    {
        private static ThreadStart s_threadStart = new C().Go;
        private static bool s_time = false;

        private long Power(long a, long b, long m)
        {
            if (b == 0) return 1;
            a %= m;
            if (b % 2 == 0)
            {
                return Power((a * a) % m, b / 2, m) % m;
            }
            else if (b % 2 == 1)
            {
                return (a * Power((a * a) % m, b / 2, m)) % m;
            }
            return 0;
        }

        private void Go()
        {
            long n = GetInt();
            long m = GetInt();

            long res = Power(3, n, m)-1;
            if (res == -1) res = m - 1;
            Wl(res);
        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            timer.Stop();
            if (s_time)
                Wl(timer.ElapsedMilliseconds);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static List<int> GetIntArr(int n)
        {
            List<int> ret = new List<int>(n);
            for (int i = 0; i < n; i++)
            {
                ret.Add(GetInt());
            }
            return ret;
        }

        private static void Wl<T>(T o)
        {
            if (o is double)
            {
                Wld((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wld((o as float?).Value, "");
            }
            else
                Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        private static void Wld(double d, string format)
        {
            Wl(d.ToString(format, CultureInfo.InvariantCulture));
        }

        public struct Tuple<T, K> : IComparable<Tuple<T, K>>, IComparable
            where T : IComparable<T>
            where K : IComparable<K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }

            #region IComparable<Tuple<T,K>> Members

            public int CompareTo(Tuple<T, K> other)
            {
                int ret = Item1.CompareTo(other.Item1);
                if (ret != 0) return ret;
                return Item2.CompareTo(other.Item2);
            }

            #endregion

            #region IComparable Members

            public int CompareTo(object obj)
            {
                if (obj is Tuple<T, K>)
                    return CompareTo((Tuple<T, K>)obj);
                return CompareTo(null);
            }

            #endregion
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

namespace CodeForces
{

	class A
	{

		private void Solve()
		{
			int n = NextInt(), m = NextInt();
			Out.WriteLine( ( pow( 3, n, m ) - 1 + m ) % m );
		}

		int pow( int a, int b, int m )
		{
			if ( b == 0 ) return 1 % m;
			int r = pow( a, b / 2, m );
			r = (int)( ( (long)r * r ) % m );
			if ( b % 2 == 1 )
			{
				r = (int)( ( (long)r * a ) % m );
			}
			return r;
		}

		#region Local wireup

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, 20000000 );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new A().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}


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

namespace Temp
{
    internal struct PointInt
    {
        public long X;

        public long Y;

        public PointInt(long x, long y)
            : this()
        {
            this.X = x;
            this.Y = y;
        }

        public PointInt(PointInt head)
            : this(head.X, head.Y)
        {
        }

        public static PointInt operator +(PointInt a, PointInt b)
        {
            return new PointInt(a.X + b.X, a.Y + b.Y);
        }

        public static PointInt operator -(PointInt a, PointInt b)
        {
            return new PointInt(a.X - b.X, a.Y - b.Y);
        }

        public static PointInt operator *(PointInt a, long k)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public static PointInt operator *(long k, PointInt a)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public bool IsInsideRectangle(long l, long b, long r, long t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }
    }

    internal struct LineInt
    {
        public LineInt(PointInt a, PointInt b)
            : this()
        {
            A = a.Y - b.Y;
            B = b.X - a.X;
            C = a.X * b.Y - a.Y * b.X;
        }

        public long A, B, C;

        public bool ContainsPoint(PointInt p)
        {
            return A * p.X + B * p.Y + C == 0;
        }
    }

    internal static class Geometry
    {
        public static long VectInt(PointInt a, PointInt b)
        {
            return a.X * b.Y - a.Y * b.X;
        }

        public static long VectInt(PointInt a, PointInt b, PointInt c)
        {
            return (b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X);
        }
    }

    internal class MatrixInt
    {
        private long[,] m_Matrix;

        public int Size
        {
            get
            {
                return m_Matrix.GetLength(0);
            }
        }

        public long Mod { get; private set; }

        public MatrixInt(int size, long mod = 0)
        {
            m_Matrix = new long[size,size];
            Mod = mod;
        }

        public MatrixInt(long[,] matrix, long mod = 0)
        {
            this.m_Matrix = matrix;
            Mod = mod;
        }

        public static MatrixInt GetIdentityMatrix(int size, long mod = 0)
        {
            long[,] matrix = new long[size,size];

            for (int i = 0; i < size; i++)
            {
                matrix[i, i] = 1;
            }

            return new MatrixInt(matrix, mod);
        }

        public long this[int i, int j]
        {
            get
            {
                return m_Matrix[i, j];
            }

            set
            {
                m_Matrix[i, j] = value;
            }
        }

        public static MatrixInt operator +(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);
            long[,] c = new long[n,n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    c[i, j] = a[i, j] + b[i, j];
                }
            }

            if (mod > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        c[i, j] %= mod;
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public static MatrixInt operator *(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);

            long[,] c = new long[n,n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                        if (mod > 0)
                        {
                            c[i, j] %= mod;
                        }
                    }
                }
            }

            return new MatrixInt(c, mod);
        }
    }

    internal static class Algebra
    {
        public static long Phi(long n)
        {
            long result = n;
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        n /= i;
                    }

                    result -= result / i;
                }
            }

            if (n > 1)
            {
                result -= result / n;
            }

            return result;
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static class Permutations
        {
            public static int[] GetRandomPermutation(int n)
            {
                int[] p = new int[n];
                for (int i = 0; i < n; i++)
                {
                    p[i] = i;
                }

                Random random = new Random();
                for (int i = n - 1; i > 0; i--)
                {
                    int j = random.Next(i + 1);
                    int tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                }

                return p;
            }
        }

        public static T[] Shuffle<T>(this T[] array)
        {
            int length = array.Length;
            int[] p = Permutations.GetRandomPermutation(length);
            T[] result = new T[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = array[p[i]];
            }

            return result;
        }

        public static MatrixInt MatrixBinPower(MatrixInt a, long n)
        {
            MatrixInt result = MatrixInt.GetIdentityMatrix(a.Size, a.Mod);

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result *= a;
                }

                a *= a;
                n >>= 1;
            }

            return result;
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a % b, out x1, out y1);
            x = y1;
            y = x1 - (a / b) * y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a / Gcd(a, b)) * b;
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            bool[] prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

        public static long GetFibonacciNumber(long n, long mod = 0)
        {
            long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };

            MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);

            return result[2, 2];
        }

        public static long[] GetFibonacciSequence(int n)
        {
            long[] result = new long[n];
            result[0] = result[1] = 1;

            for (int i = 2; i < n; i++)
            {
                result[i] = result[i - 1] + result[i - 2];
            }

            return result;
        }

        public static long GetInverseElement(long a, long mod)
        {
            long x, y;
            long g = ExtendedGcd(a, mod, out x, out y);

            if (g != 1)
            {
                return -1;
            }

            return ((x % mod) + mod) % mod;
        }

        public static long[] GetAllInverseElements(long mod)
        {
            long[] result = new long[mod];
            result[1] = 1;
            for (int i = 2; i < mod; i++)
            {
                result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;
            }

            return result;
        }
    }

    internal static class Reader
    {
        public static void ReadInt(out int a)
        {
            int[] number = new int[1];
            ReadInt(number);
            a = number[0];
        }

        public static void ReadInt(out int a, out int b)
        {
            int[] numbers = new int[2];
            ReadInt(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadInt(out int int1, out int int2, out int int3)
        {
            int[] numbers = new int[3];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadInt(out int int1, out int int2, out int int3, out int int4)
        {
            int[] numbers = new int[4];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadLong(out long a)
        {
            long[] number = new long[1];
            ReadLong(number);
            a = number[0];
        }

        public static void ReadLong(out long a, out long b)
        {
            long[] numbers = new long[2];
            ReadLong(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadLong(out long int1, out long int2, out long int3)
        {
            long[] numbers = new long[3];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadLong(out long int1, out long int2, out long int3, out long int4)
        {
            long[] numbers = new long[4];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadInt(int[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = int.Parse(list[i]);
            }
        }

        public static int[] ReadDigits()
        {
            // ReSharper disable AssignNullToNotNullAttribute
            return Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();
            // ReSharper restore AssignNullToNotNullAttribute
        }

        public static void ReadLong(long[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = long.Parse(list[i]);
            }
        }

        public static void ReadDouble(double[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = double.Parse(list[i]);
            }
        }

        public static void ReadDouble(out double a, out double b)
        {
            double[] numbers = new double[2];
            ReadDouble(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadDouble(out double int1, out double int2, out double int3)
        {
            double[] numbers = new double[3];
            ReadDouble(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }
    }

    internal static class MyMath
    {
        public static int GetMinimalPrimeDivisor(int n)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return i;
                }
            }

            return n;
        }

        public static long Sqr(long x)
        {
            return x * x;
        }
    }

    public interface IGraph
    {
        int Vertices { get; set; }

        IList<int> this[int i] { get; }

        void AddEdge(int u, int v);

        void AddOrientedEdge(int u, int v);
    }

    public class Graph : IGraph
    {
        private List<int>[] m_Edges;

        public int Vertices { get; set; }

        public IList<int> this[int i]
        {
            get
            {
                return this.m_Edges[i];
            }
        }

        public Graph(int vertices)
        {
            this.Vertices = vertices;

            this.m_Edges = new List<int>[vertices];

            for (int i = 0; i < vertices; i++)
            {
                this.m_Edges[i] = new List<int>();
            }
        }

        public void AddEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            this.AddOrientedEdge(v, u);
        }

        public void AddOrientedEdge(int first, int second)
        {
            this.m_Edges[first].Add(second);
        }

        public int[] Bfs(int start)
        {
            int[] d = new int[Vertices];
            for (int i = 0; i < Vertices; i++)
            {
                d[i] = -1;
            }

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(start);
            d[start] = 0;

            while (queue.Count > 0)
            {
                int v = queue.Dequeue();
                foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))
                {
                    queue.Enqueue(t);
                    d[t] = d[v] + 1;
                }
            }

            return d;
        }
    }

    internal class SimpleSumTable
    {
        private readonly int[,] m_Sum;

        public SimpleSumTable(int n, int m, int[,] table)
        {
            m_Sum = new int[n + 1,m + 1];

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < m + 1; j++)
                {
                    m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];
                }
            }
        }

        public int GetSum(int l, int b, int r, int t)
        {
            return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];
        }
    }

    internal class SegmentTreeSimpleInt<T>
    {
        public int Size { get; private set; }

        private readonly T[] m_Tree;

        private Func<T, T, T> m_Operation;

        private T m_Null;

        public SegmentTreeSimpleInt(int size, Func<T, T, T> operation, T nullElement, IList<T> array = null)
        {
            this.Size = size;
            this.m_Operation = operation;
            this.m_Null = nullElement;

            m_Tree = new T[4 * size];
            if (array != null)
            {
                this.Build(array, 1, 0, size - 1);
            }
        }

        private void Build(IList<T> array, int v, int tl, int tr)
        {
            if (tl == tr)
            {
                m_Tree[v] = array[tl];
            }
            else
            {
                int tm = (tl + tr) / 2;
                this.Build(array, 2 * v, tl, tm);
                this.Build(array, 2 * v + 1, tm + 1, tr);
                this.CalculateNode(v);
            }
        }

        public T GetSum(int l, int r)
        {
            return GetSum(1, 0, Size - 1, l, r);
        }

        private T GetSum(int v, int tl, int tr, int l, int r)
        {
            if (l > r)
            {
                return m_Null;
            }

            if (l == tl && r == tr)
            {
                return m_Tree[v];
            }

            int tm = (tl + tr) / 2;

            return this.m_Operation(
                GetSum(2 * v, tl, tm, l, Math.Min(r, tm)), GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
        }

        public void Update(int pos, T newValue)
        {
            Update(1, 0, Size - 1, pos, newValue);
        }

        private void Update(int v, int tl, int tr, int pos, T newValue)
        {
            if (tl == tr)
            {
                m_Tree[v] = newValue;
            }
            else
            {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                {
                    Update(2 * v, tl, tm, pos, newValue);
                }
                else
                {
                    Update(2 * v + 1, tm + 1, tr, pos, newValue);
                }
                this.CalculateNode(v);
            }
        }

        private void CalculateNode(int v)
        {
            m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);
        }
    }

    internal struct Pair<TFirst, TSecond>
    {
        public Pair(TFirst first, TSecond second)
            : this()
        {
            this.First = first;
            this.Second = second;
        }

        public TFirst First { set; get; }

        public TSecond Second { set; get; }
    }

    internal class FenwickTreeInt64
    {
        public FenwickTreeInt64(int size)
        {
            this.m_Size = size;
            m_Tree = new long[size];
        }

        public FenwickTreeInt64(int size, IList<long> tree)
            : this(size)
        {
            for (int i = 0; i < size; i++)
            {
                Inc(i, tree[i]);
            }
        }

        public long Sum(int r)
        {
            long res = 0;
            for (; r >= 0; r = (r & (r + 1)) - 1)
            {
                res += m_Tree[r];
            }
            return res;
        }

        public long Sum(int l, int r)
        {
            return Sum(r) - Sum(l - 1);
        }

        public void Inc(int i, long x)
        {
            for (; i < m_Size; i = i | (i + 1))
            {
                m_Tree[i] += x;
            }
        }

        public void Set(int i, long x)
        {
            Inc(i, x - Sum(i, i));
        }

        private int m_Size;

        private long[] m_Tree;
    }

    internal class AccumulativeDictionary<TKey> : Dictionary<TKey, int>
    {
        public new void Add(TKey key, int value = 1)
        {
            if (this.ContainsKey(key))
            {
                base[key] += value;
            }
            else
            {
                base.Add(key, value);
            }
        }

        public new int this[TKey key]
        {
            get
            {
                return this.ContainsKey(key) ? base[key] : 0;
            }
            set
            {
                this.Add(key, value);
            }
        }
    }

    internal class PriorityQueue<T>
    {
        public PriorityQueue(Comparison<T> comparison = null)
        {
            if (comparison == null)
            {
                if (typeof(T).GetInterfaces().Any(i => i == typeof(IComparable<T>)))
                {
                    m_Comparison = (a, b) => ((IComparable<T>)a).CompareTo(b);
                }
                else
                {
                    throw new ApplicationException("Add comparer");
                }
            }
            else
            {
                m_Comparison = comparison;
            }
        }

        public int Count { get; private set; }

        public void Enqueue(T item)
        {
            m_List.Add(item);
            m_Indexes.Add(item, this.Count);
            this.Count++;
            Up(this.Count);
        }

        public T Peek()
        {
            return m_List[0];
        }

        public T Dequeue()
        {
            if (this.Count > 0)
            {
                var result = m_List[0];

                Swap(0, this.Count - 1);
                m_Indexes.Remove(m_List[this.Count - 1]);
                m_List.RemoveAt(this.Count - 1);
                this.Count--;
                this.Down(1);

                return result;
            }
            throw new ApplicationException("Couldn't get element from empty queue");
        }

        public void Update(T item)
        {
            int index = m_Indexes[item];
            this.Up(index + 1);
        }

        private readonly List<T> m_List = new List<T>();

        private readonly Dictionary<T, int> m_Indexes = new Dictionary<T, int>();

        private readonly Comparison<T> m_Comparison;

        private void Up(int index)
        {
            while (index > 1 && m_Comparison.Invoke(m_List[index - 1], m_List[index / 2 - 1]) > 0)
            {
                this.Swap(index - 1, index / 2 - 1);

                index = index / 2;
            }
        }

        private void Down(int index)
        {
            while (2 * index <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index - 1]) < 0
                   || 2 * index + 1 <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index]) < 0)
            {
                if (2 * index + 1 > this.Count || m_Comparison.Invoke(m_List[2 * index - 1], m_List[2 * index]) > 0)
                {
                    this.Swap(index - 1, 2 * index - 1);
                    index = 2 * index;
                }
                else
                {
                    this.Swap(index - 1, 2 * index);
                    index = 2 * index + 1;
                }
            }
        }

        private void Swap(int i, int j)
        {
            var tmp = m_List[i];
            m_List[i] = m_List[j];
            m_List[j] = tmp;

            m_Indexes[m_List[i]] = i;
            m_Indexes[m_List[j]] = j;
        }
    }

    internal class Program
    {
        private static StreamReader m_InputStream;

        private static StreamWriter m_OutStream;

        private static void OpenFiles()
        {
            m_InputStream = File.OpenText("input.txt");
            Console.SetIn(m_InputStream);

            m_OutStream = File.CreateText("output.txt");
            Console.SetOut(m_OutStream);
        }

        private static void CloseFiles()
        {
            m_OutStream.Flush();

            m_InputStream.Dispose();
            m_OutStream.Dispose();
        }

        private static void Main()
        {
            //OpenFiles();

            new Solution().Solve();

            //CloseFiles();
        }
    }

    internal class Solution
    {
        public void Solve()
        {
            int n, m;
            Reader.ReadInt(out n, out m);

            var a = new MatrixInt(new long[,] { { 1, 0 }, { 1, 3 } }, m);

            var res = Algebra.MatrixBinPower(a, n);

            Console.WriteLine((2 * res[1, 0]) % m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

public class taskA
{
    static void Main(string[] args)
    {
        string inp = Console.ReadLine();
        string[] spl = inp.Split(' ');
        int n, m;
        n = int.Parse(spl[0]);
        m = int.Parse(spl[1]);

        if (n < 3) { Console.WriteLine(n == 1 ? "2" : "8"); return; }
        long res = pow(3,n,m);

        res = (res - (long)1+(long)m) % m;

        Console.WriteLine(res);

    }

    private static long pow(int p, int n, int m)
    {
        long res = 0;
        if (n == 0) return 1;

        if ((n % 2) == 0)
        {
            res = pow(p, n / 2, m);
            res = res * res;
            res %= m;

        }
        else
        {
            res = pow(p, n - 1, m);
            res = res * p;
            return res;
        }
        res %= m;
        return res;
    }

}


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

namespace A421{
	class Program{
		static void Main(string[] args){
            int[] nab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= nab[0]; i++)
            {
                if (a.Contains(i)) sb.Append("1 ");
                else sb.Append("2 ");
            }

            Console.WriteLine(sb.ToString());
        }
	}
}


using System;
class Program
{
    static void Main()
    {
        int[] args = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] artur = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] alex = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] answer = new int[args[0]];
        for (int i = 0; i < artur.Length; i++)
            answer[artur[i]-1] = 1;
        for (int j = 0; j < alex.Length; j++)
            answer[alex[j]-1] = 2;
        foreach(int k in answer)
            Console.Write(k+" ");
    }
}


using System;
using System.Linq;

namespace AlgoTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nab = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int[] a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int[] b = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();

            for (int i = 1; i <= nab[0]; i++)
            {
                if (a.Contains(i))
                    Console.Write(1 + " ");
                else
                    Console.Write(2 + " ");
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CF421A {
    class Program {
        static void Main(string[] args) {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Array.Sort(a);
            Array.Sort(b);

            int i = 0, j = 0;
            for(; i < a.Length && j < b.Length;) {
                if(a[i] < b[j]) {
                    Console.Write("1 ");
                    i++;
                } else if(a[i] > b[j]){
                    Console.Write("2 ");
                    j++;
                } else {
                    Console.Write("1 ");
                    i++;
                    j++;
                }
            }

            for(; i < a.Length; i++) {
                Console.Write("1 ");
            }

            for(; j < b.Length; j++) {
                Console.Write("2 ");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace asdf {
    class Program {
        static void Main(string[] args) {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = input[0], nArthur = input[1], nAlex = input[2];
            int[] arthur = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] alex = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            Array.Sort(arthur);
            int arthurIndex = 0;
            for(int i = 1; i <= n; i++) {
                if(arthurIndex < nArthur && arthur[arthurIndex] == i) {
                    Console.Write('1');
                    arthurIndex++;
                }
                else {
                    Console.Write('2');
                }
                Console.Write(' ');
            }
        }
    }
}


// Submitted by Silithus @ Macau
using System;
using System.IO;
using System.Collections.Generic;
using CCF_XOI;

namespace CoderStrike2014
{
	class Final_A
	{
		public void Solve(XOI xoi)
		{
			int N, A, B, i;
			int[] apple;

			N = xoi.ReadInt(); A = xoi.ReadInt(); B = xoi.ReadInt();
			apple = new int[N];

			for (i = 0; i < A; i++)
				apple[xoi.ReadInt() - 1] |= 0x1;

			for (i = 0; i < B; i++)
				apple[xoi.ReadInt() - 1] |= 0x2;

			for (i = 0; i < N; i++)
				xoi.o.Write((apple[i] == 0x2) ? "2 " : "1 ");
			xoi.o.WriteLine();
		}
	}

	class CS2014_Final
	{
		static void Main(string[] args)
		{
			XOI xoi = new XOI();
			(new Final_A()).Solve(xoi);
		}
	}
}

namespace CCF_XOI
{	// version 2014.02.07
	class XOI
	{
		protected StreamReader sr;
		public StreamWriter o;
		protected Queue<string> buf = new Queue<string>();
		public bool EOF = false;

		public XOI()
		{
			this.sr = new StreamReader(Console.OpenStandardInput());
			this.o = new StreamWriter(Console.OpenStandardOutput());
			this.o.AutoFlush = true;
		}

		public XOI(string in_path, string out_path)
		{
			this.sr = new StreamReader(in_path);
			this.o = new StreamWriter(out_path);
			this.o.AutoFlush = true;
		}

		public int ReadInt()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int32.Parse(s);
		}

		public long ReadLong()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int64.Parse(s);
		}

		public double ReadDouble()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Double.Parse(s);
		}

		public string ReadString()
		{
			string s = this.GetNext();
			return (s == null ? null : s);
		}

		public string ReadLine()
		{	// I will ignore current buffer and read a new line
			string s = "";
			while (s == "" && !this.EOF)
			{
				s = sr.ReadLine();
				this.EOF = (s == null);
			}
			return (this.EOF ? null : s);
		}

		protected string GetNext()
		{
			if (buf.Count == 0)
			{
				while (buf.Count == 0 && !this.EOF)
				{
					string s = sr.ReadLine();
					if (s == null)
						this.EOF = true;
					else
						foreach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
							buf.Enqueue(ss);
				}
			}

			return (this.EOF ? null : buf.Dequeue());
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pasha_and_Hamsters
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] h1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] h2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for (int i = 0; i < input[0];i++)
            {
                if (!h1.Contains(i+1) && h2.Contains(i+1))
                    Console.Write("2 ");
                else
                    Console.Write("1 ");
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nab = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int n = nab[0], a = nab[1], b = nab[2];
            var Arthur = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            var Alexander = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int[] kq = new int[n];
            for (int i = 0; i < Arthur.Length; i++)
                kq[Arthur[i] - 1] = 1;
            for (int i = 0; i < Alexander.Length; i++)
                kq[Alexander[i] - 1] = 2;
            for (int i = 0; i < kq.Length; i++)
                if (kq[i] == 0) kq[i] = 1;
            Console.WriteLine(string.Join(" ", kq));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces421
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');

            var n = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            var b = int.Parse(input[2]);

            var artur = new bool[n];
            var alex = new bool[n];
            var result = new int[n];

            foreach (var index in Console.ReadLine().Split(' ').Select(int.Parse).ToList())
            {
                artur[index-1] = true;
            }
            foreach (var index in Console.ReadLine().Split(' ').Select(int.Parse).ToList())
            {
                alex[index-1] = true;
            }

            for (int i = 0; i < n; i++)
            {
                if (artur[i] && a > 0)
                {
                    result[i] = 1;
                    a--;
                }
                else if (alex[i] && b > 0)
                {
                    result[i] = 2;
                    b--;
                }
            }

            foreach (var i in result)
            {
                Console.Write("{0} ", i);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace presummers
{
    class Program
    {
        static void Main(string[] args)
        {
            int madafaka = 0;
            int pimp = 0;
            string[] fuck = Console.ReadLine().Split(' ');
            int pasha = Convert.ToInt16(fuck[0]);
            int alex = Convert.ToInt16(fuck[0]);
            int arthur = Convert.ToInt16(fuck[0]);
            string  [] Pasha = new string[pasha];
            string[] Arthur =Console.ReadLine().Split(' ');
            string[] Alex = Console.ReadLine().Split(' ');
            for (int k = 0; k < Arthur.Length; k++)
            {
                Arthur[k] = (Convert.ToInt16(Arthur[k]) - 1).ToString();
            }
            for (int p = 0; p < Alex.Length; p++)
            {
                Alex[p] = (Convert.ToInt16(Alex[p]) - 1).ToString();
            }
            for (int i = 0; i < Arthur.Length; i++)
            {
                madafaka =Convert.ToInt16( Arthur[i]);
                Pasha[madafaka] = 1.ToString();

            }

            for (int j = 0; j < Alex.Length; j++)
            {
                pimp = Convert.ToInt16(Alex[j]);
                if (Pasha[pimp]!=1.ToString())
                {
                    Pasha[pimp] = 2.ToString();
                }

            }
            for (int i = 0; i < Pasha.Length; i++)
            {
                Console.Write(Pasha[i]+' ');
            }
            Console.ReadLine();

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var _ = Console.ReadLine().Split(' ');

        var n = int.Parse(_[0]);

        var ans = new int[n + 1];

        var arr = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);

        for (int i = 0; i < arr.Length; i++)
        {
            ans[arr[i]] = 1;
        }

        arr = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);

        for (int i = 0; i < arr.Length; i++)
        {
            ans[arr[i]] = 2;
        }

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

        Console.WriteLine();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForce
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]),
                a = int.Parse(input[1]),
                b = int.Parse(input[2]);

            int[] art = new int[a];
            string[] inp = Console.ReadLine().Split();
            for (int l = 0; l < a; l++)
                art[l] = int.Parse(inp[l]);

            int[] alx = new int[b];
            string[] inx = Console.ReadLine().Split();
            for (int i = 0; i < b; i++)
                alx[i] = int.Parse(inx[i]);

            for (int i = 0; i < n; i++)
                if (Array.IndexOf(art, i + 1) < 0)
                    Console.Write(2 + " ");
                else
                    Console.Write(1 + " ");

        }

    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var _ = Console.ReadLine().Split(' ');

        var n = int.Parse(_[0]);

        var a = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);

        Console.ReadLine();

        var hs = new HashSet<int>();

        foreach (var i in a)
        {
            hs.Add(i);
        }

        for (int i = 1; i <= n; i++)
        {
            if (hs.Contains(i))
            {
                Console.Write("1 ");
            }
            else
            {
                Console.Write("2 ");
            }
        }
        Console.WriteLine();
    }
}


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

namespace codeforce
 {
     class Program
     {
         public static void Main()
         {
             var str1 = readSplitedInts(' ');
             StringBuilder res = new StringBuilder();

             List<int> var1 = readSplitedInts(' ').ToList<int>();

             for (int i = 1; i <= str1[0]; ++i)
             {
                 if (var1.Contains(i))
                 {
                     res.Append(1).Append(' ');
                 }
                 else
                 {
                     res.Append(2).Append(' ');
                 }
             }

             Console.Out.WriteLine(res);
         }

         static int parseInt(string str)
         {
             int res = 0;

             for (int i = 0; i < str.Length; ++i)
             {
                 res *= 10;
                 switch (str[i])
                 {
                     case '0':
                         res += 0;
                         break;
                     case '1':
                         res += 1;
                         break;
                     case '2':
                         res += 2;
                         break;
                     case '3':
                         res += 3;
                         break;
                     case '4':
                         res += 4;
                         break;
                     case '5':
                         res += 5;
                         break;
                     case '6':
                         res += 6;
                         break;
                     case '7':
                         res += 7;
                         break;
                     case '8':
                         res += 8;
                         break;
                     case '9':
                         res += 9;
                         break;
                 }
             }
             return res;
         }

         static int[] readSplitedInts(char split)
         {
             var t = Console.In.ReadLine().Split(split);
             int[] res = new int[t.Length];
             for (int i = 0; i < t.Length; ++i)
             {
                 res[i] = parseInt(t[i]);
             }
             return res;
         }

         static int readInt()
         {
             return parseInt(Console.In.ReadLine());
         }
     }
 }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] t = Console.ReadLine().Split(' ');
            string[] k = (Console.ReadLine().Split(' '));
            string[] l = Console.ReadLine().Split(' ');
            int[] o = new int[k.Length];
            int[] d = new int[l.Length];
            int n = int.Parse(t[0]);
            int a = int.Parse(t[1]);
            int b = int.Parse(t[2]);
            for(int i=0; i<a; i++)
            {
                o[i] = int.Parse(k[i]);
            }
            for (int i = 0; i < b; i++)
            {
                d[i] = int.Parse(l[i]);
            }
            Array.Sort(o);
            Array.Sort(d);
            int[] otv = new int[n];
            for(int i=0; i<a; i++)
            {
                otv[o[i]-1] = 1;
            }
            for(int i=0; i<b; i++)
            {
                otv[d[i]-1] = 2;
            }
            for(int i=0 ; i<n; i++)
            {
                Console.Write(otv[i] + " ");
            }
            Console.ReadLine();

        }
    }
}


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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ns= Console.ReadLine().Split(' ');
            int n = int.Parse(ns[0]);
            int[] m1 = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
            int[] m2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            bool[] m = new bool[n];
            foreach (int i in m1)
            {
                m[i-1] = true;
            }
            string r = "";
            for (int i=0;i<n;i++)
            {
                if (m[i])
                    r += "1 ";
                else
                    r += "2 ";
            }
            r = r.Remove(r.Length - 1, 1);
            Console.WriteLine(r);
        }
    }
}


// Problem: 421A - Pasha and Hamsters
// Author: Gusztav Szmolik

using System;

class PashaAndHamsters
    {
    public static int Main ()
        {
        string line;
        string[] words;
        if (!ReadLine (out line) || !ReadWords (line, 3, out words))
            return -1;
        byte n;
        if (!ReadByte (words[0], 1, 100, out n))
            return -1;
        byte a;
        byte b;
        if (!ReadByte (words[1], 1, n, out a) || !ReadByte (words[2], 1, n, out b))
            return -1;
        byte[] ans = new byte[n];
        Array.Clear (ans,0,n);
        byte countDistributedApples = 0;
        if (!ReadLine (out line) || !ReadWords (line, a, out words))
            return -1;
        for (byte i = 0; i < a; i++)
            {
            byte apple;
            if (!ReadByte (words[i], 1, n, out apple))
                return -1;
            apple--;
            if (ans[apple] == 0)
                {
                ans[apple] = 1;
                countDistributedApples++;
                }
            else
                return -1;
            }
        if (!ReadLine (out line) || !ReadWords (line, b, out words))
            return -1;
        for (byte i = 0; i < b; i++)
            {
            byte apple;
            if (!ReadByte (words[i], 1, n, out apple))
                return -1;
            apple--;
            if (ans[apple] == 0)
                {
                ans[apple] = 2;
                countDistributedApples++;
                }
            else if (ans[apple] > 1)
                return -1;
            }
        if (countDistributedApples != n)
            return -1;
        for (byte i = 0; i < n; i++)
            {
            Console.Write (ans[i]);
            Console.Write (i+1 == n ? "\n" : " ");
            }
        return 0;
        }

    static bool ReadLine (out string line)
        {
        line = Console.ReadLine ();
        return (line == null ? false : true);
        }

    static bool ReadWords (string line, byte numWord, out string[] words)
        {
        words = line.Split ();
        return (words.Length == numWord ? true : false);
        }

    static bool ReadByte (string number, byte lowLimit, byte highLimit, out byte result)
        {
        result = 0;
        if (!Byte.TryParse (number, out result))
            return false;
        return (result < lowLimit || result > highLimit ? false : true);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n, a, b;
            n = int.Parse(s[0]);
            a = int.Parse(s[1]);
            b = int.Parse(s[2]);
            bool[] who = new bool[n];
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < a; i++)
            {
                who[int.Parse(s[i])-1] = true;
            }
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                if (who[i])
                {
                    Console.Write("1 ");
                }
                else
                {
                    Console.Write("2 ");
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] count = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int[] num1 = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int[] num2 = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            string s = "";
            for (int i = 1; i <= count[0]; i++)
            {
                if (num1.Contains(i))
                    s += "1 ";
                else s += "2 ";
            }

                Console.WriteLine(s);

        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] v = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));
            int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));
            int[] al = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));
            Array.Sort(ar);
            Array.Sort(al);
            string res = "";
            for (int i = 0; i < v[0]; i++)
            {
                res += (ar.Contains(i + 1)) ?
                        "1 " : "2 ";
            }
            Console.WriteLine(res.Trim());
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Threading;
using System.Linq;

class TEST{
	static void Main(){
		var d=Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));
		int[] F=new int[d[0]];
		for(int i=0;i<d[0];i++)F[i]=0;
		var d2=Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));
		for(int i=0;i<d2.Length;i++)F[d2[i]-1]=1;

		for(int i=0;i<d[0];i++){
			if(i==0){
				Console.Write("{0}",(F[i]==1)?1:2);
			}else{
				Console.Write(" {0}",(F[i]==1)?1:2);
			}
		}
		Console.WriteLine("");
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maxim
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] numba = input.Split(' ');
            int n = Convert.ToInt32(numba[0]);
            int a = Convert.ToInt32(numba[1]);
            int b = Convert.ToInt32(numba[2]);
            input = Console.ReadLine();
            numba = input.Split(' ');
            string[] artur = input.Split(' ');
            input = Console.ReadLine();
            numba = input.Split(' ');
            string[] oleksandr = input.Split(' ');
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < oleksandr.Length; j++)
                {
                    if (Convert.ToInt32(oleksandr[j]) - 1 == i)
                    {
                        ans[i] = 2;
                        break;
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < artur.Length; j++)
                {
                    if (Convert.ToInt32(artur[j]) - 1 == i)
                    {
                        ans[i] = 1;
                        break;
                    }
                }
            }
            for (int i = 0; i < ans.Length; i++)
            {
                Console.Write(ans[i] + " ");
            }
        }
    }
}


using System;
using System.Linq;

namespace CodForces
{

    public class Place : IComparable
    {
        public long Count { get; set; }
        public double R { get; set; }

        public int CompareTo(object obj)
        {

            var pl = (Place)obj;

            if (this.R == pl.R)
            {
                return 0;
            }

            if (this.R < pl.R)
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }
    }

    class Program
    {

        class Scanner
        {
            string[] _s;
            int _i;

            readonly char[] _cs = new char[] { ' ' };

            public Scanner()
            {
                _s = new string[0];
                _i = 0;
            }

            public string Next()
            {
                if (_i < _s.Length) return _s[_i++];
                _s = Console.ReadLine().Split(_cs, StringSplitOptions.RemoveEmptyEntries);
                _i = 0;
                return _s[_i++];
            }

            public int NextInt()
            {
                return int.Parse(Next());
            }

            public long NextLong()
            {
                return long.Parse(Next());
            }
        }

        public static double Len(long x1, long y1, long x2, long y2)
        {
            return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
        }

        static void Main()
        {
            var scanner = new Scanner();
            var n = scanner.NextInt();
            var a = scanner.NextInt();
            var b = scanner.NextInt();

            var A = new int[n];
            for (int i = 0; i < a; i++)
            {
                var temp = scanner.NextInt();
                A[temp-1] = 1;
            }

            for (int i = 0; i < b; i++)
            {
                var temp = scanner.NextInt();
                A[temp-1] = 2;
            }

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


// Submitted by Silithus @ Macau
using System;
using System.IO;
using System.Collections.Generic;
using CCF_XOI;

namespace CoderStrike2014
{
	class R1_D
	{
		List<int>[] link;
		bool[] vis;
		XOI xoi;

		private void DFS(int u)
		{
			vis[u] = true;
			foreach (int v in link[u])
				if (!vis[v])
					DFS(v);

			xoi.o.Write("{0} ", u + 1);
		}

		public void Solve(XOI _xoi)
		{
			int N, M, i;

			this.xoi = _xoi;
			N = xoi.ReadInt(); M = xoi.ReadInt();
			vis = new bool[N];
			link = new List<int>[N];
			for (i = 0; i < N; i++)
				link[i] = new List<int>();

			while (M-- > 0)
				link[xoi.ReadInt() - 1].Add(xoi.ReadInt() - 1);

			for (i = 0; i < N; i++)
				if (!vis[i])
					DFS(i);

			xoi.o.WriteLine();
		}
	}

	class CS2014_R1
	{
		static void Main(string[] args)
		{
			XOI xoi = new XOI();
			(new R1_D()).Solve(xoi);
		}
	}
}

namespace CCF_XOI
{	// version 2014.02.07
	class XOI
	{
		protected StreamReader sr;
		public StreamWriter o;
		protected Queue<string> buf = new Queue<string>();
		public bool EOF = false;

		public XOI()
		{
			this.sr = new StreamReader(Console.OpenStandardInput());
			this.o = new StreamWriter(Console.OpenStandardOutput());
			this.o.AutoFlush = true;
		}

		public XOI(string in_path, string out_path)
		{
			this.sr = new StreamReader(in_path);
			this.o = new StreamWriter(out_path);
			this.o.AutoFlush = true;
		}

		public int ReadInt()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int32.Parse(s);
		}

		public long ReadLong()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int64.Parse(s);
		}

		public double ReadDouble()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Double.Parse(s);
		}

		public string ReadString()
		{
			string s = this.GetNext();
			return (s == null ? null : s);
		}

		public string ReadLine()
		{	// I will ignore current buffer and read a new line
			string s = "";
			while (s == "" && !this.EOF)
			{
				s = sr.ReadLine();
				this.EOF = (s == null);
			}
			return (this.EOF ? null : s);
		}

		protected string GetNext()
		{
			if (buf.Count == 0)
			{
				while (buf.Count == 0 && !this.EOF)
				{
					string s = sr.ReadLine();
					if (s == null)
						this.EOF = true;
					else
						foreach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
							buf.Enqueue(ss);
				}
			}

			return (this.EOF ? null : buf.Dequeue());
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var _ = Console.ReadLine().Split(' ');

        var n = int.Parse(_[0]);

        var ans = new int[n + 1];

        var arr = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);

        for (int i = 0; i < arr.Length; i++)
        {
            ans[arr[i]] = 2;
        }

        arr = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);

        for (int i = 0; i < arr.Length; i++)
        {
            ans[arr[i]] = 2;
        }

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

        Console.WriteLine();
    }
}