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

namespace Dima_and_Friends
{
    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 void Main(string[] args)
        {
            int n = Next();
            int sum = 0;

            for (int i = 0; i < n; i++)
            {
                sum += Next();
            }

            int count = 0;
            for (int i = 1; i < 6; i++)
            {
                if ((sum + i-1)%(n + 1) != 0)
                    count++;
            }

            writer.WriteLine(count);
            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.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine()) + 1;
        var f = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var ans = 0;
        for (int i = 0; i < 5; i++)
        {
            if ((f.Sum() + i) % n != 0)
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}


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

namespace ConsoleApp1
{
    internal class Program
    {

        private static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input) +1;

            var inputs = Array.ConvertAll(Console.ReadLine().Split(' '), s => int.Parse(s));
            int count = 0;
            int fingers = inputs.Sum();
            if ((fingers + 1) % n != 1)
                count++;
            if ((fingers + 2) % n != 1)
                count++;

            if ((fingers + 3) % n != 1)
                count++;

            if ((fingers + 4) % n != 1)
                count++;

            if ((fingers + 5) % n != 1)
                count++;

            Console.WriteLine(count);
            //  Console.ReadKey();
        }

        // Console.ReadKey();

    }

}


/*
 * Сделано в SharpDevelop.
 * Пользователь: alexey
 * Дата: 16.11.2012
 * Время: 19:15
 *
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading;
using System.IO;
using System;

namespace round_159
{
	class Program
	{
		public static int ReadInt(){

				return int.Parse(Console.ReadLine());

			}

		public static string[] ReadStrArr(){

				return Console.ReadLine().Split(' ');

			}

	    public static int ToInt(Object a){

			return int.Parse(a.ToString());

			}

		public static void print(object[] mas){

		for (int i =0;i<mas.Length;i++)
			Console.Write(mas[i].ToString()+" ");
		}

	public static void Main(string[] args)
		{

		int n = ReadInt();
		int sum = 0;
		string[]  s = ReadStrArr();
		for (int i = 0; i < n; i++) {
			sum +=ToInt(s[i]);

		};

		n++;
		int k =0;
		int p = sum % n;

		for (int i = 1; i < 6; i++) {
			if( (p+i) % n !=1) k++;

		}

		Console.WriteLine(k);

		//Console.ReadKey();

		}

	}

}


#region Usings

using System;
using System.Linq;

#endregion

namespace A {
    internal class Program {
        private static void Main() {
            var n = Convert.ToInt32(Console.ReadLine());
            var sum = Console.ReadLine().Split(' ').Select(_ => Convert.ToInt32(_)).Sum();

            var res = 0;
            if ((sum + 1)%(n + 1) != 1) {
                res++;
            }
            if ((sum + 2)%(n + 1) != 1) {
                res++;
            }
            if ((sum + 3)%(n + 1) != 1) {
                res++;
            }
            if ((sum + 4)%(n + 1) != 1) {
                res++;
            }
            if ((sum + 5)%(n + 1) != 1) {
                res++;
            }

            Console.WriteLine(res);
        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Test
    {
        static void GiveMeAnswer(ref sbyte friends,ref int fingers)
        {
            friends++;

           // friends++;
            byte Answer = 0 ;
            byte num=0;
            for (byte i = 1; i <= 5; i++)
            {
                if (fingers % friends != 0)
                { Answer++; fingers++; }
                else { fingers = 1; /*friends--; */}
            }
            Console.WriteLine(Answer);

        }
        static void Main()
        {
            string[] Nfing;
            sbyte friends = sbyte.Parse(Console.ReadLine());
            if (friends >100 && friends <0)
            { friends = 5; } // защита от идиота. Absolute random value :3
            Nfing = Console.ReadLine().Split(' ');
            int fingers =0;
            for (byte i = 0; i<friends && i<Nfing.Length; i++)
            {
                if(Nfing[i]=="" || sbyte.Parse(Nfing[i])>5 || sbyte.Parse(Nfing[i])<1)
         // если не все друзья были указаны,либо среди друзей затесались инопланетяне, то считаем что было показано 0 пальцев
                {}
                else { fingers =  fingers + int.Parse(Nfing[i]); }

            }
            //Console.WriteLine(fingers);
            GiveMeAnswer(ref friends, ref fingers);

           // Console.ReadKey();

        }

    }
}


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

namespace _158Csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            //int[] A = new int[n];
            string s = Console.ReadLine();
            string[] p = s.Split(new Char[] { ' ' });
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += Convert.ToInt32(p[i]);
            }
            int count = 0;
            for (int i = 1; i <= 5; i++)
            {
                int pos = (sum + i) % (n + 1);
                if (pos != 1)
                {
                    count++;
                }
            }
            Console.WriteLine(count);

            /*  A

            int n = Convert.ToInt32(Console.ReadLine());
            int[,] A = new int[n, 2];

            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                string[] p = s.Split(new Char[] { ' ' });
                A[i, 0] = Convert.ToInt32(p[0]);
                A[i, 1] = Convert.ToInt32(p[1]);
            }
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i != j)
                    {
                        if (A[i, 0] == A[j, 1])
                        {
                            count++;
                        }
                    }
                }
            }

            Console.WriteLine(count);
            */

            /*  B
            int n = Convert.ToInt32(Console.ReadLine());
            int x = 0;
            for (int i = 1; i <= n - 1; i++)
            {
                x += (n - i) * i;
            }
            x += n;
            Console.WriteLine(x);
             */

            /*  C
            string s = Console.ReadLine();
            string[] p = s.Split(new Char[] { ' ' });

            int n = Convert.ToInt32(p[0]);
            int m = Convert.ToInt32(p[1]);

            int x = Math.Min(n, m) + 1;
            Console.WriteLine(x);

            for (int i = 0; i < x; i++)
            {
                Console.WriteLine(i + " " + (x - i - 1));
            }
             */

        }
    }
}


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 А
    {
        private static ThreadStart s_threadStart = new А().Go;
        private static bool s_time = false;

        private void Go()
        {
            int n = GetInt();
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += GetInt();
            }
            sum %= (1 + n);

            int ret = 5;
            for (int i = 1; i <= 5; i++)
            {
                if ((sum + i) % (n + 1) == 1) ret--;
            }
            Wl(ret);
        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 200 * 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>>
            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
        }

        #endregion
    }
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            string[] str = Console.ReadLine().Split(' ');
            int[] array = new int[n];
            for (int i = 0; i < n; i++ )
            {
                array[i] = int.Parse(str[i]);
            }
            int arValue = array.Sum<int>(x => x);

            int summ = 0;
            for (int i = 1; i <= 5; i++ )
            {
                int total = i + arValue - 1;
                //Console.WriteLine(i+"   "+total+"  "+total % (n + 1));
                if (total % (n + 1) == 0)
                {
                    //summ++;
                }
                else
                {
                    summ++;
                }
            }

            Console.WriteLine(summ);
        }
    }
}


using System;

namespace Test
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            int n = int.Parse (Console.ReadLine ());
            int[] f = new int[n];
            int k = 0;
            int s = 0;
            string[] tmp = Console.ReadLine ().Split (' ');
            for (int i = 0; i != n; i++) {
                f [i] = int.Parse (tmp[i]);
                s += f [i];
            }
            n++;
            for (int i = 1; i != 6; i++) {
                if((s + i) % n != 1){
                    k++;
                }
            }
            Console.Write (k);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Numerics;
namespace ConsoleApplication25
{
    class Solution
    {
        static void Main(string[] args)
        {
            var init = int.Parse(Console.ReadLine());

            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var ans = 0;

            for (int i = 1; i <= 5; i++)
            {
                if ( (i + p.Sum() - 1)%(init + 1) == 0)
                {
                    ans++;
                }
            }

            Console.WriteLine(5 - ans);
                Console.ReadLine();
        }
    }
}


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

namespace SubSequences
{
    class Program
    {

        static void Main(string[] args)
        {
            int friends = Convert.ToInt32(System.Console.ReadLine());
            var fingers = System.Console.ReadLine().Split(' ');//.Select(int.Parse).Sum(a=>a);

            int fingersShown = 0;

            foreach (var finger in fingers)
            {
                fingersShown += int.Parse(finger);
            }

            int variants = 0;

            foreach (var i in new int[]{1,2,3,4,5})
            {
                if ((fingersShown + i) % (friends + 1) != 1)
                {
                    variants++;
                }
            }

            System.Console.WriteLine(variants);

        }

    }
}


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

namespace CodeForces
{
    class R167_Div2_A
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int[] a = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                sum += a[i];
            }

            int cnt = 0;
            for (int i = 1; i <= 5; i++)
                if ((sum + i) % (n + 1) != 1)
                    cnt++;

            Console.WriteLine(cnt);

        }
    }
}


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

namespace Codeforce
{

    class Program
    {
        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 void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            var data = parseInt(Console.ReadLine());

            int total = data.Sum();

            n++;

            int cnt = 0;
            for (int i = 1; i <= 5; i++)
            {
                if ((total + i) % n != 1)
                    ++cnt;
            }

            Console.WriteLine(cnt);
        }
    }
}


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

class Program
{
    private static int[] arrc;

    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine())+1;

        var s = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
            .Select(int.Parse)
            .Sum();

        var res = 0;

        var f = 1;
        while (f<=5)
        {
            if ((s + f++)%n!= 1) res++;
        }

        Console.WriteLine(res);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Point
		{
			public int x;

			public int y;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c || (x.c == y.c && x.r < y.r))
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

		public static void WriteYESNO(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

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

		public static List<int> getList()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> getLongList()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int Min(int x, int y)
		{
			return Math.Min(x, y);
		}

		public static int Max(int x, int y)
		{
			return Math.Max(x, y);
		}

		public static int Abs(int x)
		{
			return Math.Abs(x);
		}

		public static int getInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long getLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public static bool Equal(int x, int y, int x1, int y1)
		{
			return x == x1 && y == y1;
		}

		public class Edge
		{
			public int v;

			public int w;
		}

		public class Vertex
		{
			public List<Edge> edges;

			public int ct;

			public bool was;
		}

		public static bool canAuto(string s, string s1)
		{
			var l = 0;
			for (var i = 0; i < s1.Length; ++i)
			{
				while (l < s.Length && s[l] != s1[i])
					l++;
				if (l == s.Length)
					return false;
				l++;
			}
			return true;
		}

		public static bool canArray(string s, string s1)
		{
			var l = s.ToCharArray().ToList();
			var l1 = s1.ToCharArray().ToList();
			l.Sort();
			l1.Sort();
			if (l.Count != l1.Count)
				return false;

			for (var i = 0; i < l.Count; ++i)
				if (l[i] != l1[i])
					return false;

			return true;
		}

		public static bool canBoth(string s, string s1)
		{
			var l = s.ToCharArray().ToList();
			var l1 = s1.ToCharArray().ToList();
			l.Sort();
			l1.Sort();
			var ll = 0;
			for (var i = 0; i < l1.Count; ++i)
			{
				while (ll < l.Count && l[ll] != l1[i])
					ll++;
				if (ll == l.Count)
					return false;
				ll++;
			}

			return true;
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var n = getInt();
			var l = getList();
			var s = l.Sum();
			var ans = 0;
			for (var i = 1; i <= 5; ++i)
				if ((s + i) % (n + 1) != 1)
					ans++;
			Console.WriteLine(ans);
			Console.ReadLine();
		}
	}
}


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

namespace olympic
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int ans = 0,sum = 0;
            string[] temp = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; ++i)
            {
                sum += Convert.ToInt32(temp[i]);
            }
            for (int i = 1; i <= 5; ++i)
            {
                if ((sum + i) % (n+1) != 1) ++ans;
            }
            Console.Write(ans);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int sum = 0;
            string [] s =Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                sum = sum + int.Parse(s[i]);

            int ans = 0;
            for (int i = 1; i <= 5; i++)
            {
                if ((sum + i) % (n + 1) != 1)
                    ans++;
            }
            Console.WriteLine(ans);
           // Console.ReadKey();
        }

    }
}


using System;

namespace ConsoleApplication1
{
    class Test
    {
        static void GiveMeAnswer(ref sbyte friends,ref int fingers)
        {
            friends++;
            byte Answer = 0 ;
            for (byte i = 1; i <= 5; i++)
            {
                if (fingers % friends != 0)
                { Answer++; fingers++; }
                else { fingers = 1;}
            }
            Console.WriteLine(Answer);
        }
        static void Main()
        {
            string[] Nfing;
            sbyte friends = sbyte.Parse(Console.ReadLine());
            if (friends >100 && friends <0)
            { friends = 5; } // защита от идиота. Absolute random value :3
            Nfing = Console.ReadLine().Split(' ');
            int fingers =0;
            for (byte i = 0; i<friends && i<Nfing.Length; i++)
            {
                if(Nfing[i]=="" || sbyte.Parse(Nfing[i])>5 || sbyte.Parse(Nfing[i])<1)
         // если не все друзья были указаны,либо среди друзей затесались инопланетяне, то считаем что было показано 0 пальцев
                {}
                else { fingers =  fingers + int.Parse(Nfing[i]); }

            }
            GiveMeAnswer(ref friends, ref fingers);
        }

    }
}


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

namespace COJ
{
    class MainClass
    {
        /// <summary>
        /// Author: Luismo
        /// Idea:
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            //TextReader tr = Console.In;
            //TextWriter tw = Console.Out;
            //Console.SetIn(new StreamReader(@"d:\lmo.in"));
            //Console.SetOut(new StreamWriter(@"d:\lmo.out"));
            //string [] data = Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);

            int n = int.Parse(Console.ReadLine());
            string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int fingers = 0;
            for (int i = 0; i < data.Length; i++)
            {
                fingers += int.Parse(data[i]);
            }

            n++;
            int cnt = 0;
            //int k = n % fingers;
            for (int i = 1; i < 6; i++)
            {
                if ((fingers + i) % n != 1)
                    cnt++;
            }

            Console.WriteLine(cnt);
            //PrintMt(distance);

            //Console.Out.Close();
            //Console.SetIn (tr);
            //Console.SetOut(tw);
            Console.ReadLine();
        }

        private static string PrintArray(int[] arr)
        {
            string s = "";
            for (int i = 0; i < arr.Length; i++)
            {
                s += arr[i] + " ";
                //Console.Write(distribution[i] + " ");
            }
            //Console.WriteLine();
            return s.Trim();
        }

        public static double EuclideanDistance(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }

        static double ABS(double a)
        {
            if (a < 0)
                a *= -1;
            return a;
        }

        static int ABS(int a)
        {
            if (a < 0)
                a *= -1;
            return a;
        }

        static int Min(int a, int b)
        {
            if (a < b)
                return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a < b)
                return b;
            return a;
        }

        static bool IsPrime(long n)
        {
            if (n == 2 || n == 3 || n <= 0)
                return true;
            if (n % 2 == 0 || n == 1 || n % 3 == 0)
                return false;

            for (int i = 5; i * i <= n; i += 2)
            {
                if (n % i == 0)
                    return false;
            }
            return true;
        }

        static bool RepeatedNumbers(int year)
        {
            bool[] arr = new bool[10];
            while (year > 0)
            {
                if (arr[year % 10])
                    return true;

                arr[year % 10] = true;
                year /= 10;
            }
            return false;
        }

        static void PrintMt(int[,] mt)
        {
            for (int i = 0; i < mt.GetLength(0); i++)
            {
                for (int j = 0; j < mt.GetLength(1); j++)
                {
                    Console.Write(mt[i, j] + " ");
                }
                Console.WriteLine();
            }
        }

    }

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

        public override string ToString()
        {
            return string.Format("[{0} , {1}]", x, y);
        }

    }

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

        public override string ToString()
        {
            return string.Format("{0} {1}", x, y);
        }

        public double EuclidDistance(Point p1)
        {
            double dist = Math.Sqrt((this.x - p1.x) * (this.x - p1.x) + (this.y - p1.y) * (this.y - p1.y));
            return dist;
        }

    }

}


using System;
using System.Linq;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int rez = 0;
            int count = a.Sum() % (n + 1);
            for (int i = 1; i <= 5; i++)
            {
                if ((count + i) % (n + 1) !=  1)
                    rez++;
            }
            Console.WriteLine(rez);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;
using System.Globalization;
using System.Threading;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), tz => int.Parse(tz));
            int sum = a.Sum();
            int ans = 0;
            for (int i = 1; i <= 5; i++) {
                if ((sum + i) % (n + 1) != 1) {
                    ans++;
                }
            }
            Console.Write(ans);
            //Console.ReadKey();
        }
    }
}


using System;

namespace AllProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            _272A_DimaAndFriends.Run();

        }
    }
    class _272A_DimaAndFriends
    {
        public static void Run()
        {
            var n = byte.Parse(Console.ReadLine().Trim());
            var n2 = n + 1;
            var l = Console.ReadLine().Trim().Split(' ');
            short sum = 0;
            for (byte i = 0; i < n; i++)
                sum += byte.Parse(l[i]);

            byte ctr = 0;
            for (var i = sum; i < sum + 5; i++)
            {
                if (i % n2 != 0) ++ctr;
            }

            Console.WriteLine(ctr);
            Console.ReadLine();
        }
    }
}


using System;

namespace pr2
{
    class Program
    {
        public static void Main(string[] args)
        {int n,s,o,p;
            n=Convert.ToInt16(Console.ReadLine());
            int[] a;
            a= new int[n];
        string [] line = Console.ReadLine().Split();
            s=0;
        for (int i=0; i<n; i++)
            {
            s+=Convert.ToInt16(line[i]);

            }

        o=s%(n+1);
        p=0;
        for (int i=0;i<5;i++){
        if (o>0) {
        s++;
        o=s%(n+1);
        p++;
            } else {
            s++;
            o=s%(n+1);
            }
        }
        Console.WriteLine(Convert.ToString(p));
            //Console.ReadKey(true);
        }
    }
}


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

namespace CodeForces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
			new Template().Solve();
		}

		private void Solve()
		{
			var n = cin.NextInt();
			var f = new int[n];
			for (var i = 0; i < n; i++)
			{
				f[i] = cin.NextInt();
			}
			var sum = f.Sum();
			var count = 0;
			for (var i = 1; i <= 5; i++)
			{
				if ((sum + i) % (n + 1) != 1)
				{
					count++;
				}
			}
			Console.WriteLine(count);
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = new[] { ' ' };

		public string Next()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

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

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace contest1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_167A();
        }
        public static void solve_167A()
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string[] tests = Console.ReadLine().Split(' ');
            int[] fingers = Array.ConvertAll(tests, int.Parse);

            int sum = 0;
            for (int i = 0; i < fingers.Length; i++)
            {
                sum += fingers[i];
            }

            int count = 0;

            for (int i = 1; i <= 5; i++)
            {
                if ((sum + i) % (n + 1) != 1)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
        public static void solve_50A()
        {
            string[] nk = Console.ReadLine().Split(' ');

            long n = Convert.ToInt64(nk[0]);
            long k = Convert.ToInt64(nk[1]);

            long x = 0;

            x = (k + n - 1) / n;
            /*if (k <= n)
            {
                x = 1;
            }
            else if (k % n != 0)
            {
                x = k / n + 1;
            }
            else
            {
                x = k / n;
            }
            */
            Console.WriteLine(x);
        }
        public static void solve_72A()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            // How to proof it?
            Console.WriteLine(2 * n - (n / 2));
        }
    }
}


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

namespace COJ
{
    class MainClass
    {
        /// <summary>
        /// Author: Luismo
        /// Idea:
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            //TextReader tr = Console.In;
            //TextWriter tw = Console.Out;
            //Console.SetIn(new StreamReader(@"d:\lmo.in"));
            //Console.SetOut(new StreamWriter(@"d:\lmo.out"));
            //string [] data = Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);

            int n = int.Parse(Console.ReadLine());
            string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int fingers = 0;
            for (int i = 0; i < data.Length; i++)
            {
                fingers += int.Parse(data[i]);
            }

            n++;
            int cnt = 0;
            //int k = n % fingers;
            for (int i = 1; i < 6; i++)
            {
                if ((fingers + i) % n != 1)
                    cnt++;
            }

            Console.WriteLine(cnt);
            //PrintMt(distance);

            //Console.Out.Close();
            //Console.SetIn (tr);
            //Console.SetOut(tw);
            Console.ReadLine();
        }

        private static void NumberOfPosibleTriangles(int n)
        {

        }

        private static void Knapsack(int[,] mt)
        {
            // KnapSackProblem
            int n = 0, w = 0;

            int[] weights = new int[w];
            int[] values = new int[n];

            //int[,] mt = new int[n, w];
            for (int i = 0; i < w; i++)
                mt[0, i] = 0;
            for (int i = 0; i < n; i++)
                mt[i, 0] = 0;
        }

        private static string PrintArray(int[] arr)
        {
            string s = "";
            for (int i = 0; i < arr.Length; i++)
            {
                s += arr[i] + " ";
                //Console.Write(distribution[i] + " ");
            }
            //Console.WriteLine();
            return s.Trim();
        }

        public static double EuclideanDistance(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }

        static double ABS(double a)
        {
            if (a < 0)
                a *= -1;
            return a;
        }

        static int ABS(int a)
        {
            if (a < 0)
                a *= -1;
            return a;
        }

        static int Min(int a, int b)
        {
            if (a < b)
                return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a < b)
                return b;
            return a;
        }

        static bool IsPrime(long n)
        {
            if (n == 2 || n == 3 || n <= 0)
                return true;
            if (n % 2 == 0 || n == 1 || n % 3 == 0)
                return false;

            for (int i = 5; i * i <= n; i += 2)
            {
                if (n % i == 0)
                    return false;
            }
            return true;
        }

        static bool RepeatedNumbers(int year)
        {
            bool[] arr = new bool[10];
            while (year > 0)
            {
                if (arr[year % 10])
                    return true;

                arr[year % 10] = true;
                year /= 10;
            }
            return false;
        }

        static void PrintMt(int[,] mt)
        {
            for (int i = 0; i < mt.GetLength(0); i++)
            {
                for (int j = 0; j < mt.GetLength(1); j++)
                {
                    Console.Write(mt[i, j] + " ");
                }
                Console.WriteLine();
            }
        }

    }

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

        public override string ToString()
        {
            return string.Format("[{0} , {1}]", x, y);
        }

    }

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

        public override string ToString()
        {
            return string.Format("{0} {1}", x, y);
        }

        public double EuclidDistance(Point p1)
        {
            double dist = Math.Sqrt((this.x - p1.x) * (this.x - p1.x) + (this.y - p1.y) * (this.y - p1.y));
            return dist;
        }

    }

}


using System;

namespace MyFirstProject
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Int32 n = Convert.ToInt32(Console.ReadLine());
            Int32 friend = 0;

            string[] splitString = Console.ReadLine().Split(' ');
            int x;

            for (int i = 0; i < n; i++)
            {
                int.TryParse(splitString[i], out x);
                friend += x;
                //friend += Convert.ToInt32(Console.ReadLine());
            }
            n++;
            Int32 res = 0;
            for (int i = 1; i < 6; i++)
            {
                if (((friend+i-1) % (n)) != 0)
                {
                    //Console.WriteLine((friend + i)+" % "+n+" = "+((friend+i) % (n)));
                    res++;
                }
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Linq;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine());
    var x = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
    var res = Enumerable.Range(1, 5).Count(i => (i + x) % (n+1) != 1);
    Console.WriteLine(res);
  }
}


using System;
using System.Linq;

namespace CSharp
{
    public class _272A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int sum = Console.ReadLine().Split().Select(token => int.Parse(token)).Sum();

            int ways = 0;
            for (int fingers = 1; fingers <= 5; fingers++)
            {
                if ((sum + fingers) % (n + 1) != 1)
                {
                    ways++;
                }
            }

            Console.WriteLine(ways);
        }
    }
}


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

public class A167
{
    public static void Main()
    {
            new A167().Entry();
    }//Main

    void Entry()
    {
        int n = intRead() + 1;
        int[] arary = intSplit(' ');
        int cnt = 0;
        foreach (int item in arary)
        {
            cnt += item;
        }//foreach item
        cnt %= n;
        int res = 0;
        for (int i = 1; i <= 5; i++)
        {
            if ((cnt + i) % n != 1)
                res++;
        }//for i
        Console.WriteLine(res);
    }

    string strRead()
    {
        return Console.ReadLine();
    }

    int intRead()
    {
        return int.Parse(Console.ReadLine());
    }

    long longRead()
    {
        return long.Parse(Console.ReadLine());
    }

    double doubleRead()
    {
        return double.Parse(Console.ReadLine());
    }

    string[] strSplit(char a)
    {
        return Console.ReadLine().Split(a);
    }

    int[] intSplit(char a)
    {
        return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse);
    }

    long[] longSplit(char a)
    {
        return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse);
    }

    double[] doubleSplit(char a)
    {
        return Array.ConvertAll<string, double>(Console.ReadLine().ToString().Split('a'), double.Parse);
    }

}//Template


using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int friendsNumber = int.Parse(Console.ReadLine()) + 1;
            int peoples = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x)).Sum();

            int ways = 0;
            for (int i = 1; i <= 5; i++)
            {
                if ((peoples + i) % friendsNumber == 1)
                {
                    continue;
                }
                ways++;
            }

            Console.WriteLine(ways);
            Console.Read();
        }
    }
}


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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;

    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static bool foo(string s1, string s2)
        {
            for (int i = 0; i < s1.Length; i++)
            {
                for (int e = 0; e < s2.Length; e++)
                {
                    if (s1[i] == s2[e])
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            string[] s = Console.ReadLine().Split();
            int[] m = new int[n];
            int x = 0;
            for (int i = 0; i < n; i++)
            {
                x += int.Parse(s[i]);
            }
            int ans = 0;
            for (int i = 1; i <= 5; i++)
            {
                if ((i + x) % (n + 1) != 1)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace olimp
{
    class Program
    {
        private static void ShowArray<T>(T array)
        {
            foreach (var arr in (IEnumerable)array)
                Console.Write(arr+" ");
        }

        private static void Main(string[] args)
        {
            int friends_count = int.Parse(Console.ReadLine());
            int[] friends_hand = (from str in Console.ReadLine().Split(' ', '\t') select int.Parse(str)).ToArray();
            int summ_hand = 0;
            int result = 0;

            foreach (var hand in friends_hand)
                summ_hand += hand;

            for (int i = 1; i <= 5; i++)
            {
                if ((summ_hand + i - 1) % (friends_count + 1) != 0)
                    result++;
            }
            Console.WriteLine(result);
            Console.ReadKey();
        }
    }
}


using System;
using System.Linq;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine());
    var x = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
    var res = Enumerable.Range(1, 5).Count(i => (i + x) % n != 1);
    Console.WriteLine(res);
  }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int sum = 0;
            string [] s =Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                sum = sum + int.Parse(s[i]);
            if ((n + 1) % 2 == 0)
            {
                if (sum % 2 == 0)
                    Console.WriteLine(2);
                else
                    Console.WriteLine(3);
            }
            else
            {
                if (sum % 2 == 0)
                    Console.WriteLine(3);
                else
                    Console.WriteLine(2);
            }
            //Console.ReadKey();
        }

    }
}


using System;

namespace MyFirstProject
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Int32 n = Convert.ToInt32(Console.ReadLine());
            Int32 friend = 0;
            for (int i = 0; i < n; i++)
            {
                friend += Convert.ToInt32(Console.ReadLine());
            }
            n++;
            Int32 res = 0;
            for (int i = 1; i < 6; i++)
            {
                if (((friend+i-1) % (n)) != 0)
                {
                    Console.WriteLine((friend + i)+" % "+n+" = "+((friend+i) % (n)));
                    res++;
                }
            }
            Console.WriteLine(res);
        }
    }
}


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

namespace olympic
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int ans = 0,sum = 0;
            string[] temp = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; ++i)
            {
                sum += Convert.ToInt32(temp[i]);
            }
            for (int i = 1; i <= 5; ++i)
            {
                if ((sum + i) % n != 1) ++ans;
            }
            Console.Write(ans);
        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Test
    {
        static void GiveMeAnswer(ref sbyte friends,ref int fingers)
        {
            friends++;
            friends++;
            byte Answer = 0 ;
            byte num=0;
            for (byte i = 1; i <= 5; i++)
            {
                if ((fingers++) % friends != 0)
                { Answer++; }
                else { fingers = 1; friends--; }
            }
            Console.WriteLine(Answer);

        }
        static void Main()
        {
            string[] Nfing;
            sbyte friends = sbyte.Parse(Console.ReadLine());
            if (friends >100 && friends <0)
            { friends = 5; } // защита от идиота. Absolute random value :3
            Nfing = Console.ReadLine().Split(' ');
            int fingers =0;
            for (byte i = 0; i<friends && i<Nfing.Length; i++)
            {
                if(Nfing[i]=="" || sbyte.Parse(Nfing[i])>5 || sbyte.Parse(Nfing[i])<1)
         // если не все друзья были указаны,либо среди друзей затесались инопланетяне, то считаем что было показано 0 пальцев
                {}
                else { fingers =  fingers + int.Parse(Nfing[i]); }

            }
            //Console.WriteLine(fingers);
            GiveMeAnswer(ref friends, ref fingers);

            //Console.ReadKey();

        }

    }
}


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

namespace olympic
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int ans = 0,sum = 0;
            for (int i = 0; i < n; ++i)
            {
                sum += Int32.Parse(Console.Read().ToString());
                Console.Read();
            }
            for (int i = 1; i <= 5; ++i)
            {
                if (((sum + i) % (n+1)) != 1) ++ans;
            }
            Console.Write(ans);
        }
    }
}


using System;
using System.Linq;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine());
    var x = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
    var res = Enumerable.Range(1, 5).Count(i => (i + x) % n != 1);
    Console.WriteLike(res);
  }
}


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

namespace Problem2
{
    class B818
    {
        static void Main(string[] args)
        {
            string[] arr = Console.ReadLine().Split();
            int n = int.Parse(arr[0]);
            int m = int.Parse(arr[1]);
            string[] arr1 = Console.ReadLine().Split();
            int[] l = new int[m];
            for (int i = 0; i < m; i++)
            {
                l[i] = int.Parse(arr1[i]);
            }

            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < m-1; i++)
            {
                if (l[i + 1] - l[i] > 0)
                {
                    a[l[i] - 1] = l[i + 1] - l[i];

                }
                else {
                    a[l[i] - 1] = n-l[i] + l[i+1];
                }
                b[l[i] - 1]++;
            }

            for (int i = 0; i < n; i++)
            {
                if (b[i] > 1 && b[i]!=m-1|| b[i]==0) {
                    Console.WriteLine(-1);
                    return;
                }
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(a[i]+" ");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int N, M;
        sc.Make(out N, out M);
        var L = sc.ArrInt;
        var res = new int[N];
        for(int i = 0; i < M - 1; i++)
        {
            var v = (L[i + 1] - L[i] + N) % N;
            if (v == 0) v = N;
            if (res[L[i] - 1] == 0)
            {
                res[L[i] - 1] = v;
            }
            if (res[L[i] - 1] != v) Fail(-1);
        }
        if (res.Any(v => v == 0)) Fail(-1);
        var use = new bool[N + 1];
        for (int i = 0; i < N; i++)
        {
            if (use[res[i]]) Fail(-1);
            use[res[i]] = true;
        }
        Console.WriteLine(string.Join(" ", res));
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var words = Console.ReadLine().Split(' ');
            long n, m;
            n = Convert.ToInt64(words[0]);
            m = Convert.ToInt64(words[1]);
            words = Console.ReadLine().Split(' ');
            long[] numbers = new long[n+1];
            long[] steps = new long[m + 1];
            for (int i = 1; i <= m; ++i)
            {
                steps[i] = Convert.ToInt64(words[i - 1]);
            }
            for (int i = 1; i < m; ++i)
            {
                long diff = 0;
                if (steps[i+1] <= steps[i])
                {
                    diff += n - steps[i] + steps[i + 1];
                } else
                {
                    diff = steps[i+1] - steps[i];
                }
                if (numbers[steps[i]] != 0 && numbers[steps[i]] != diff)
                {
                    Console.WriteLine(-1);
                    return;
                }
                numbers[steps[i]] = diff;
            }
            for (int i = 1; i < n + 1; ++i)
            {
                if (numbers[i] == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            for (int i = 1; i<n+1; ++i)
            {
                Console.Write(numbers[i] + " ");
            }

        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {

                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];
                if (d[a-1] != 0)
                {
                    if (b != d[a-1]) { Console.WriteLine(-1); return; }
                }

                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            d[i] = j;
                            j++;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.Write(d[i]+" ");
                i++;
            }
        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {

                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];
                if (d[a-1] != 0)
                {
                    if (b != d[a]) { Console.WriteLine(-1); return; }
                    else break;
                }

                if (f[b] == 1) { Console.WriteLine(-1);return;}
                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            d[i] = j;
                            j++;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.Write(d[i]+" ");
                i++;
            }
        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {
                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];

                if (f[b] == 1) { Console.WriteLine(-1);return;}
                f[b]++;
                d[a - 1] = b;
                if (a == m[i]) break;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            m[i] = j;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.WriteLine(d[i]+" ");
                i++;
            }
        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {

                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];
                if (d[a-1] != 0)
                {
                    if (b != d[a-1]) { Console.WriteLine(-1); return; }
                }

                if (f[b] == 1) { Console.WriteLine(-1);return;}
                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            d[i] = j;
                            j++;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.Write(d[i]+" ");
                i++;
            }
        }
    }
}


using System;
using System.Linq;
namespace _818B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            int[] l = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] a = new int[n];
            for (int i = 1; i < m; i++)
            {
                int prev = l[i - 1], curr = l[i] + (l[i] <= l[i - 1] ? n : 0), diff = curr - prev;
                a[prev - 1] = diff;
            }
            Console.WriteLine(a.All(x => x > 0) ? string.Join(" ", a) : "-1");
        }
    }
}


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

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, M;
    private int[] L;

    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        M = int.Parse(line[1]);
        L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    public void Solve()
    {
        Scan();
        int[] ans = (new int[N]).Select(i => int.MinValue).ToArray();
        for (int i = 0; i < M - 1; i++)
        {
            if (ans[L[i] - 1] == int.MinValue)
            {
                int j = L[i + 1] - L[i];
                if (j <= 0)
                {
                    j += N;
                }
                ans[L[i] - 1] = j;
            }
            else
            {
                int j = L[i] + ans[L[i] - 1];
                if (j > N)
                {
                    j -= N;
                }
                if (L[i + 1] != j)
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
        }
        if (ans.Any(i => i == int.MinValue))
        {
            Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(string.Join(" ", ans));
    }
}


using System;
using System.Collections.Generic;
namespace _818B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            int[] l = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] a = new int[n];
            bool good = true;
            bool[] seen = new bool[n + 1];
            for (int i = 0; i < m - 1; i++)
            {
                int diff = (l[i + 1] + n - l[i]) % n;
                if (a[l[i] - 1] == 0)
                {
                    a[l[i] - 1] = diff;
                    seen[diff] = true;
                }
                else if (a[l[i] - 1] != diff)
                {
                    good = false;
                    break;
                }
            }
            good = !seen[0];
            if (good)
            {
                Queue<int> notSeen = new Queue<int>();
                for (int i = 1; i <= n; i++)
                    if (!seen[i])
                        notSeen.Enqueue(i);
                for (int i = 0; i < n; i++)
                    if (a[i] == 0 && notSeen.Count > 0)
                        a[i] = notSeen.Dequeue();
                    else if (a[i] == 0 && notSeen.Count == 0)
                    {
                        good = false;
                        break;
                    }
                if (notSeen.Count > 0)
                    good = false;
            }
            Console.WriteLine(good ? string.Join(" ", a) : "-1");
        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {
                if (d[a] != 0) break;
                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];

                if (f[b] == 1) { Console.WriteLine(-1);return;}
                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            d[i] = j;
                            j++;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.Write(d[i]+" ");
                i++;
            }
        }
    }
}


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

namespace ConsoleApp35
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inp0[0];
            int m = inp0[1];
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<int> l = new List<int>();
            int[] a = new int[n];
            bool check = true;
            int[] numbers = new int[n + 1];
            for (int i = 0; i < m - 1; i++)
            {

                if (s[i + 1] > s[i])
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = (s[i + 1] - s[i]) % n;
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    else
                    {
                        a[s[i] - 1] = (s[i + 1] - s[i]) % n;
                        numbers[a[s[i] - 1]]++;
                    }

                }
                else
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = n - s[i];
                        e += s[i + 1];
                        e = e % n;
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    a[s[i] - 1] = n - s[i];
                    a[s[i] - 1] += s[i + 1];
                    a[s[i] - 1] = a[s[i] - 1] % n;
                    numbers[a[s[i] - 1]]++;
                }
            }
            if ( !check)
            {
                Console.WriteLine(-1);
            }

            else
            {
                List<int> li = new List<int>();
                for (int i = 1; i < n+1; i++)
                {
                    if (numbers[i]==0)
                    {
                        li.Add(i);
                    }
                }
                int count = 0;
                for (int i = 0; i < n; i++)
                {
                    if (a[i]==0)
                    {
                        a[i] = li[count];
                        count++;
                    }

                }
                if (a.Distinct().Count() != n)
                {
                    Console.WriteLine(-1);
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        Console.Write(a[i] + " ");
                    }
                }
            }
        }

    }
}


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

namespace ConsoleApp35
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inp0[0];
            int m = inp0[1];
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<int> l = new List<int>();
            int[] a = new int[n];
            for (int i = 0; i < m-1; i++)
            {
                if (s[i+1]>s[i])
                {
                    a[s[i]-1] = (s[i + 1] - s[i]) % n;

                }
                else
                {
                    a[s[i]-1] = n - s[i];
                    a[s[i]-1] += s[i + 1];
                    a[s[i]-1] = a[s[i]-1] % n;
                }
            }
            if (a.Distinct().Count() != n)
            {
                Console.WriteLine(-1);
            }

            else
            {
                foreach (int item in a)
                {
                    if (item == 0)
                    {
                        Console.Write(n + " ");
                    }
                    else
                    {
                        Console.Write(item + " ");
                    }
                }
            }
        }

    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {
                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];

                if (f[b] == 1) { Console.WriteLine(-1);return;}

                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            m[i] = j;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.WriteLine(d[i]+" ");
                i++;
            }
        }
    }
}


using System;

namespace CodefCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int[] m = new int[105];
            int[] d = new int[105];
            int[] f = new int[105];

            int n = int.Parse(tokens[0]);
            int k=  int.Parse(tokens[1]);

            int i=0;
            tokens = Console.ReadLine().Split();

            while (i < k)
            {
                m[i] = int.Parse(tokens[i]);
                i++;
            }i = 1;

            int a= m[0];
            int b;

            while (i < k)
            {
                if (d[a-1] != 0) break;
                if (m[i] - a > 0)b = m[i] - a;
                else b = n - a + m[i];

                if (f[b] == 1) { Console.WriteLine(-1);return;}
                f[b]++;
                d[a - 1] = b;
                a = m[i];
                i++;
            }i = 0;int j = 1;

            while (i < n)
            {
                if (d[i] == 0)
                {

                    while (j <= n)
                    {
                        if (f[j] == 0)
                        {
                            d[i] = j;
                            j++;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }i = 0;

            while (i < n)
            {
                Console.Write(d[i]+" ");
                i++;
            }
        }
    }
}


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

namespace ConsoleApp35
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inp0[0];
            int m = inp0[1];
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<int> l = new List<int>();
            int[] a = new int[n];
            bool check = true;
            int[] numbers = new int[n + 1];
            for (int i = 0; i < m - 1; i++)
            {

                if (s[i + 1] > s[i])
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = (s[i + 1] - s[i]) % n;
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    else
                    {
                        a[s[i] - 1] = (s[i + 1] - s[i]) % n;
                        if (a[s[i] - 1]==0)
                        {
                            a[s[i] - 1] = n;
                        }
                        numbers[a[s[i] - 1]]++;
                    }

                }
                else
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = n - s[i];
                        e += s[i + 1];
                        e = e % n;
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    a[s[i] - 1] = n - s[i];
                    a[s[i] - 1] += s[i + 1];
                    a[s[i] - 1] = a[s[i] - 1] % n;
                    if (a[s[i] - 1] == 0)
                    {
                        a[s[i] - 1] = n;
                    }
                    numbers[a[s[i] - 1]]++;
                }
            }
            if ( !check)
            {
                Console.WriteLine(-1);
            }

            else
            {
                List<int> li = new List<int>();
                for (int i = 1; i < n+1; i++)
                {
                    if (numbers[i]==0)
                    {
                        li.Add(i);
                    }
                }
                int count = 0;
                for (int i = 0; i < n; i++)
                {
                    if (a[i]==0)
                    {
                        a[i] = li[count];
                        count++;
                    }

                }
                if (a.Distinct().Count() != n)
                {
                    Console.WriteLine(-1);
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        Console.Write(a[i] + " ");
                    }
                }
            }
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int N, M;
        sc.Make(out N, out M);
        var L = sc.ArrInt;
        var res = new int[N];
        for(int i = 0; i < M - 1; i++)
        {
            var v = (L[i + 1] - L[i] + N) % N;
            if (v == 0) v = N;
            if (res[L[i] - 1] == 0)
            {
                res[L[i] - 1] = v;
            }
            if (res[L[i] - 1] != v) Fail(-1);
        }
        var use = new bool[N + 1];
        for (int i = 0; i < N; i++)
        {
            if (use[res[i]]) Fail(-1);
            use[res[i]] = true;
        }
        var idx = 1;
        for(int i = 0; i < N; i++)
        {
            if (res[i] != 0) continue;
            while (use[idx]) idx++;
            res[i] = idx++;
        }
        Console.WriteLine(string.Join(" ", res));
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


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

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

            s = Console.ReadLine().Split();

            int[] a = new int[m];
            for (int i=0;i<m;i++) a[i]=int.Parse(s[i]);

            int[] res = new int[n+1];
            HashSet<int> nums = new HashSet<int>();
            for (int i = 1; i <= n; i++) nums.Add(i);

            int x = 0;
            bool ok = true;
            for (int i = 0; i < a.Length - 1; i++)
            {
                if (a[i + 1] > a[i])
                    x = a[i + 1] - a[i];
                else
                    x = n - a[i] + a[i + 1];
                if ((res[a[i]]==0 && !nums.Contains(x)) || (res[a[i]] > 0 && res[a[i]] != x))
                {
                    ok = false;
                    break;
                }

                res[a[i]] = x;
                nums.Remove(x);
            }

            if (ok)
            {
                for (int i=1;i<=n;i++)
                {
                    if (res[i] == 0)
                    {
                        res[i] = nums.First();
                        nums.Remove(res[i]);
                    }
                    Console.Write(res[i] + " ");
                }
            }
            else
            {
                Console.Write(-1);
            }
         }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var words = Console.ReadLine().Split(' ');
            long n, m;
            n = Convert.ToInt64(words[0]);
            m = Convert.ToInt64(words[1]);
            words = Console.ReadLine().Split(' ');
            long[] numbers = new long[n+1];
            long[] steps = new long[m + 1];
            bool[] usernumbers = new bool[n + 1];
            for (int i = 1; i <= m; ++i)
            {
                steps[i] = Convert.ToInt64(words[i - 1]);
            }
            for (int i = 1; i < m; ++i)
            {
                long diff = 0;
                if (steps[i + 1] <= steps[i])
                {
                    diff += n - steps[i] + steps[i + 1];
                } else
                {
                    diff = steps[i + 1] - steps[i];
                }
                if (numbers[steps[i]] != 0 && numbers[steps[i]] != diff)
                {
                    Console.WriteLine(-1);
                    return;
                } else if (numbers[steps[i]] != 0 && numbers[steps[i]] == diff)
                {
                    continue;
                }
                if (usernumbers[diff] == true)
                {
                    Console.WriteLine(-1);
                    return;
                }
                numbers[steps[i]] = diff;
                usernumbers[diff] = true;
            }
            for (int i = 1, j = 1; i <= n && j <=n;)
            {
                if (usernumbers[j] == true)
                {
                    ++j;
                    continue;
                }
                if (numbers[i] == 0)
                {
                    numbers[i] = j;
                    ++j;++i;
                } else
                {
                    ++i;
                }
            }
            for (int i = 1; i<n+1; ++i)
            {
                Console.Write(numbers[i] + " ");
            }

        }
    }
}


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

namespace Permutation_Game
{
    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 void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var l = new int[m];
            for (int i = 0; i < l.Length; i++)
            {
                l[i] = Next() - 1;
            }

            var nn = new int[n];
            var f = new bool[n + 1];
            for (int i = 1; i < l.Length; i++)
            {
                int delta = l[i] - l[i - 1];
                if (delta <= 0)
                    delta += n;
                if (f[delta])
                {
                    if (nn[l[i - 1]] != delta)
                    {
                        writer.WriteLine("-1");
                        writer.Flush();
                        return;
                    }
                }
                else
                {
                    if (nn[l[i - 1]] != 0)
                    {
                        writer.WriteLine("-1");
                        writer.Flush();
                        return;
                    }
                    nn[l[i - 1]] = delta;
                    f[delta] = true;
                }
            }

            int index = 1;
            for (int i = 0; i < nn.Length; i++)
            {
                if (nn[i] == 0)
                {
                    while (index < f.Length && f[index])
                    {
                        index++;
                    }
                    if (index >= f.Length)
                    {
                        writer.WriteLine("-1");
                        writer.Flush();
                        return;
                    }
                    nn[i] = index++;
                }
            }

            foreach (int i in nn)
            {
                writer.Write(i);
                writer.Write(' ');
            }
            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;
namespace _818B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            int[] l = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] a = new int[n];
            bool good = true;
            bool[] seen = new bool[n + 1];
            for (int i = 0; i < m - 1; i++)
            {
                int diff = (l[i + 1] + n - l[i]) % n;
                if (diff == 0) diff = n;
                if (a[l[i] - 1] == 0)
                {
                    a[l[i] - 1] = diff;
                    seen[diff] = true;
                }
                else if (a[l[i] - 1] != diff)
                {
                    good = false;
                    break;
                }
            }
            if (good)
            {
                Queue<int> notSeen = new Queue<int>();
                for (int i = 1; i <= n; i++)
                    if (!seen[i])
                        notSeen.Enqueue(i);
                for (int i = 0; i < n; i++)
                    if (a[i] == 0 && notSeen.Count > 0)
                        a[i] = notSeen.Dequeue();
                    else if (a[i] == 0 && notSeen.Count == 0)
                    {
                        good = false;
                        break;
                    }
                if (notSeen.Count > 0)
                    good = false;
            }
            Console.WriteLine(good ? string.Join(" ", a) : "-1");
        }
    }
}


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

namespace ConsoleApp35
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inp0[0];
            int m = inp0[1];
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<int> l = new List<int>();
            int[] a = new int[n];
            bool check = true;
            int[] numbers = new int[n + 1];
            for (int i = 0; i < m - 1; i++)
            {

                if (s[i + 1] > s[i])
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = (s[i + 1] - s[i]) % n;
                        if (e == 0)
                        {
                            e = n;
                        }
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    else
                    {
                        a[s[i] - 1] = (s[i + 1] - s[i]) % n;
                        if (a[s[i] - 1]==0)
                        {
                            a[s[i] - 1] = n;
                        }
                        numbers[a[s[i] - 1]]++;
                    }

                }
                else
                {
                    if (a[s[i] - 1] > 0)
                    {
                        int e = n - s[i];
                        e += s[i + 1];
                        e = e % n;
                        if (e==0)
                        {
                            e = n;
                        }
                        if (e != a[s[i] - 1])
                        {
                            check = false;
                            break;
                        }
                    }
                    a[s[i] - 1] = n - s[i];
                    a[s[i] - 1] += s[i + 1];
                    a[s[i] - 1] = a[s[i] - 1] % n;
                    if (a[s[i] - 1] == 0)
                    {
                        a[s[i] - 1] = n;
                    }
                    numbers[a[s[i] - 1]]++;
                }
            }
            if ( !check)
            {
                Console.WriteLine(-1);
            }

            else
            {
                List<int> li = new List<int>();
                for (int i = 1; i < n+1; i++)
                {
                    if (numbers[i]==0)
                    {
                        li.Add(i);
                    }
                }
                int count = 0;
                for (int i = 0; i < n; i++)
                {
                    if (a[i]==0)
                    {
                        a[i] = li[count];
                        count++;
                    }

                }
                if (a.Distinct().Count() != n)
                {
                    Console.WriteLine(-1);
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        Console.Write(a[i] + " ");
                    }
                }
            }
        }

    }
}