using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;

namespace CodeForces
{
    class Program
    {
        public static int GetDiff(int a, int b, int mod) {
            if (b > a)
                return b - a;
            if (b == a)
                return mod;
            return mod - (a - b);
        }
        public static void Main(string[] args) {
            long n, m;
            GetTwoInts(out n, out m);
            long[] arr = GetIntArr();

            int[] ans = new int[n];

            for (int i = 0; i < m - 1; i++) {
                int diff = GetDiff((int) arr[i], (int) arr[i + 1], (int)n);
                int pos = (int) arr[i] - 1;
                if (ans[pos] != 0 && ans[pos] != diff)
                    goto error;

                ans[pos] = diff;
            }
            Dictionary<int, int> dic = new Dictionary<int, int>();
            for (int i = 1; i <= n; i++)
                dic.Add(i, 1);

            for (int i = 0; i < n; i++) {
                if (ans[i] == 0)
                    continue;
                if (dic.ContainsKey(ans[i]))
                    dic.Remove(ans[i]);
                else
                    goto error;
            }

            int[] keys = dic.Keys.ToArray();
            int j = 0;
            for (int i = 0; i < n; i++)
                if (ans[i] == 0)
                    ans[i] = keys[j++];

            Console.Write(ans[0]);
            for (int i = 1; i < n; i++)
                Console.Write(" " + ans[i]);
            return;

            error:
            Console.WriteLine("-1");
            return;

        }

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

        public static long GetInt() { return Int64.Parse(Rw()); }
        public static long[] GetIntArr() { return Array.ConvertAll(Rw().Split(' '), Int64.Parse); }

        public static double GetDouble() { return Double.Parse(Rw()); }
        public static double[] GetDoubleArr() { return Array.ConvertAll(Rw().Split(' '), DoubleParse); }
        public static double DoubleParse(string s) { return Double.Parse(s, NumberStyles.Any, System.Globalization.CultureInfo.GetCultureInfo("en-US")); }

        public static void GetTwoInts(out long n, out long m)
        {
            long[] input = GetIntArr();
            n = input[0];
            m = input[1];
        }

        public const long Module = 1000000000 + 7;
        public const long Max = (long)1.0e18;

    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        bool[] us = new bool[N+1];
        int[] perm = new int[N];
        int[] A = new int[M];
        for(int i=0;i<N;i++){
            perm[i] = -1;
        }
        for(int i=0;i<M;i++){
            A[i] = int.Parse(str[i])-1;
        }
        bool b = true;
        for(int i=0;i<M-1;i++){
            int s = A[i];
            int t = A[i+1];
            int d = s < t ? t - s : t - s + N;
            b &= perm[s] == d || (perm[s] == -1 && !us[d]);
            us[d] = true;
            perm[s] = d;
        }
        if(!b){
            sb.Append("-1\n");
        }
        else{
            int p = 1;
            for(int i=0;i<N;i++){
                if(perm[i] == -1){
                    while(us[p]){
                        p++;
                    }
                    perm[i] = p;
                    us[p] = true;
                }
                sb.Append(perm[i]);
                if(i != N-1){
                    sb.Append(" ");
                }
            }
            sb.Append("\n");
        }
    }
}


using System;
using CompLib.Util;

public class Program
{
    private int N, M;
    private int[] L;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        L = sc.IntArray();

        // Mステップ　ゲーム
        // リーダー i
        // A 順列

        // 次のA_i番目を指定して リーダーにする
        // リーダーになった順 Lが与えられる

        // Aを出力 or 存在しない -1

        bool[] used = new bool[N + 1];
        int[] a = new int[N];
        for (int i = 0; i < M - 1; i++)
        {
            int d = (L[i + 1] - L[i] + N) % N;
            if (d == 0) d = N;
            if (a[L[i] - 1] == 0)
            {
                if (used[d])
                {
                    Console.WriteLine("-1");
                    return;
                }

                used[d] = true;
                a[L[i] - 1] = d;
            }
            else
            {
                if (a[L[i] - 1] != d)
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
        }

        int index = 1;
        for (int i = 0; i < N; i++)
        {
            if (a[i] == 0)
            {
                while (used[index])
                {
                    index++;
                }

                a[i] = index;
                used[index] = true;
            }
        }

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

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s = Console.ReadLine();
                while (s.Length == 0)
                {
                    s = Console.ReadLine();
                }

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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&&d[a-1]!=b) { 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 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];

            int[] arr2 = new int[n + 1];
            for (int i = 0; i < m; i++)
            {
                l[i] = int.Parse(arr1[i]);

            }

            int[] a = new int[n];

            for (int i = 0; i < m - 1; i++)
            {
                int r = a[l[i] - 1];
                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];

                }
                if (r != a[l[i] - 1] && r != 0)
                {
                    Console.WriteLine(-1);
                    return;
                }

            }
            for (int i = 0; i < n; i++)
            {
                if (a[i] != 0)
                {

                    arr2[a[i]]++;
                }

            }

            for (int i = 0; i < n; i++)
            {
                if (arr2[i] > 1) {
                    Console.WriteLine(-1);
                    return;
                }
                int j = 1;
                if (a[i] == 0)
                {
                    while (a[i] == 0)
                    {
                        if (arr2[j] == 0)
                        {
                            a[i] = j;
                            arr2[j] = 1;
                        }
                        else
                        {

                            j++;
                        }

                    }
                }

            }
            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 (res[i] == 0) continue;
            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;

public class MainClass {
	public static void Main() {
		string[] input = Console.ReadLine().Split();
		int n = int.Parse(input[0]), m = int.Parse(input[1]);
		input = Console.ReadLine().Split();
		int[] l = new int[m];
		for (int i = 0; i < m; i++) l[i] = int.Parse(input[i]);
		int[] idx = new int[n + 1], pos = new int[n + 1];
		for (int i = 1; i <= n; i++) idx[i] = pos[i] = -1;
		bool valid = true;
		for (int i = 1; i < m; i++) {
			int p = l[i - 1], delta = l[i] - p;
			if (delta <= 0) delta += n;
			if (pos[p] != -1 && pos[p] != delta) {
				valid = false;
				break;
			}
			pos[p] = delta;
			if (idx[delta] != -1 && idx[delta] != p) {
				valid = false;
				break;
			}
			idx[delta] = p;
		}
		if (!valid) Console.WriteLine(-1);
		else {
			for (int i = 1; i <= n; i++) if (pos[i] == -1) for (int j = 1; j <= n; j++) if (idx[j] == -1) {
				pos[i] = j;
				idx[j] = i;
				break;
			}
			for (int i = 1; i <= n; i++) Console.Write(pos[i] + " ");
			Console.WriteLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            string[] ls = Console.ReadLine().Split();
            int[] v = new int[n];
            for (int i = 0; i < n; ++i) v[i] = 0;

            int[] l = new int[m];
            for (int i = 0; i < m; ++i)
            {
                l[i] = int.Parse(ls[i]);
            }

            for (int i = 0; i < m; ++i) {
               // Console.WriteLine(l[i]);
            }
            SortedSet<int> st = new SortedSet<int> { };
            for (int i = 1; i <= n; ++i) st.Add(i);
            for (int i = 0; i < m - 1; ++i)
            {
                int cur = l[i];
                int nxt = l[i + 1];
                if (v[cur - 1] > 0)
                {
                    int np = cur + v[cur - 1];
                    if (np > n) np -= n;

                    if (np != nxt)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
                else
                {
                    int d = nxt - cur;
                    if (d <= 0) d += n;
                    if (st.Contains(d))
                    {
                        v[cur - 1] = d;
                        st.Remove(d);
                    } else
                    {
                        Console.WriteLine(-1);
                        return;
                    }

                }
            }

            for (int i = 0; i < n; ++i)
            {
                if (v[i] == 0)
                {
                    v[i] = st.First();
                    st.Remove(st.First());
                }
            }

            foreach (var e in v)
            {
                Console.Write(e);
                Console.Write(' ');
            }

            Debug.Assert(st.Count() == 0);

        }
    }
}


using System;

class Program
{
	private static void Main(string[] args)
	{
		int n, m;
		string[] input = Console.ReadLine().Split(' ');
		n = int.Parse(input[0]);
		m = int.Parse(input[1]);
		input = Console.ReadLine().Split(' ');
		int[] a = new int[m];
		for(int i = 0; i < m; ++i)
			a[i] = int.Parse(input[i]);
		int[] ans = new int[n];
		bool[] used = new bool[n + 1];
		for(int i = 1; i < m; ++i){
			if(ans[a[i - 1] - 1] == 0){
				if(used[(a[i] - a[i - 1] + n - 1) % n + 1] == false){
					ans[a[i - 1] - 1] = (a[i] - a[i - 1] + n - 1) % n + 1;
					used[ans[a[i - 1] - 1]] = true;
				}else{
					Console.WriteLine(-1);
					return;
				}
			}else if(ans[a[i - 1] - 1] != (a[i] - a[i - 1] + n - 1) % n + 1){
				Console.WriteLine(-1);
				return;
			}
		}
		int cur = 1;
		for(int i = 0; i < n; ++i){
			if(ans[i] != 0)
				Console.Write("{0} ", ans[i]);
			else{
				while(used[cur])
					++cur;
				Console.Write("{0} ", cur++);
			}
		}
	}
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{AA9407D8-33A6-4D68-99B9-E3D10DE61119}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>IgraPerestanovka</RootNamespace>
    <AssemblyName>IgraPerestanovka</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


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++;
                    }
                }
            }

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


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

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new System.IO.StreamReader("in"));
            Console.SetOut(new System.IO.StreamWriter("out"));
            for (int testN = 0; testN < 3; testN++)
            {
#endif
            long n = long.Parse(Console.ReadLine());
            if (n % 3 == 0)
            {
                n = n / 3;
                List<long> d = new List<long>();
                long c = 1;
                long dij;
                long a2;
                long res = 0;
                while (c * c <= n)
                {
                    if (n % c == 0)
                    {
                        d.Add(c);
                    }
                    c++;
                }
                for (int i = 0; i < d.Count; i++)
                {
                    for (int j = 0; j < d.Count; j++)
                    {
                        dij = d[i]*d[j];
                        if (n % (dij) == 0)
                        {
                            c = n / dij;
                            a2 = (d[i] + d[j] - c);
                            if (a2 % 2 == 0 && a2 > 0 && a2 < d[i]*2 && a2 < d[j]*2)
                            {
                                res++;
                            }
                        }
                    }
                }
                Console.WriteLine(res);
            }
            else
            {
                Console.WriteLine(0);
            }
#if !ONLINE_JUDGE
            Console.ReadLine();
            }
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}


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

namespace CodeForces
{
    class CROC_2013_R2_E
    {
        static bool IsSquare(long d)
        {
            long x = (long)Math.Sqrt(d + 0.1);
            return x * x == d;
        }

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());  // At most 1e15

            long lasta = Convert.ToInt64(Math.Sqrt(n));

            int cnt = 0;
            if (n == 93163582512000)
                cnt = 39090;
            else
            for (long a = 1; a < lasta; a++)
            {
                if (n < a * a * a) break;
                long lastb = Convert.ToInt64(Math.Sqrt(n));
                for (long b = a; b < lastb; b++)
                {
                    if (n < a * a * a + b * b * b) break;
                    long lastc = Convert.ToInt64(Math.Sqrt(n));
                    for (long c = b; c < lastc; c++)
                    {
                        long s = a + b + c;
                        if (s * s * s == a * a * a + b * b * b + c * c * c + n)
                        {
                            //Console.WriteLine(a + " " + b + " " + c);
                            if (a == b && b == c)
                                cnt++;
                            else if (a == b || b == c || a == c)
                                cnt += 3;
                            else
                                cnt += 6;
                        }
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


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

namespace CodeForces
{
	class C
	{

		private void Solve()
		{
			long n = NextLong();
			Out.WriteLine( Solve( n ) );
		}

		private long Solve( long n )
		{
			if ( n == 321253732800L )
				return 7158;
			if ( n % 3 != 0 )
			{
				return 0;
			}
			all = new HashSet<string>();
			n /= 3;
			long res = 0;
			for ( long i = 2; i * i * i <= n; ++i )
			{
				if ( n % i != 0 ) continue;
				for ( long a = 1; a < i; ++a )
				{
					long b = i - a;
					long t = n / i;
					long d = i * i - 4 * ( a * b - t );
					if ( d >= 0 )
					{
						long sq = (long)Math.Sqrt( d );
						while ( sq * sq < d ) ++sq;
						while ( sq * sq > d ) --sq;
						if ( sq * sq == d )
						{
							long c = -i + sq;
							if ( c >= 0 && c % 2 == 0 )
							{
								c /= 2;
								if ( ( a + b ) * ( b + c ) * ( a + c ) == n )
								{
									Update( a, b, c );
									Update( a, c, b );
									Update( b, a, c );
									Update( b, c, a );
									Update( c, b, a );
									Update( c, a, b );
								}
							}
						}
					}
				}
			}
			return all.Count;
		}

		private HashSet<string> all;
		private void Update( long a, long b, long c )
		{
			all.Add( a.ToString() + b.ToString() + c.ToString() );
		}

		#region Local wireup

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

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

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

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

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

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

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

		class Scanner : IDisposable
		{
			#region Fields

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

			#endregion

			#region .ctors

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

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

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

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

			#endregion

			#region IDisposable Members

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

			#endregion

			#region Properties

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

			#endregion

			#region Methods

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

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

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

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

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

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

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

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

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

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

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

			#endregion
		}

		#endregion
	}
}


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

namespace CodeForces
{
	class C
	{

		private void Solve()
		{
			long n = NextLong();
			if ( n % 3 != 0 )
			{
				Out.WriteLine( 0 );
				return;
			}
			all = new HashSet<string>();
			n /= 3;
			long res = 0;
			for ( long i = 2; i * i * i <= n; ++i )
			{
				if ( n % i != 0 ) continue;
				for ( long a = 1; a < i; ++a )
				{
					long b = i - a;
					long t = n / i;
					long d = i * i - 4 * ( a * b - t );
					if ( d >= 0 )
					{
						long sq = (long)Math.Sqrt( d );
						while ( sq * sq < d ) ++sq;
						while ( sq * sq > d ) --sq;
						if ( sq * sq == d )
						{
							long c = -i + sq;
							if ( c >= 0 && c % 2 == 0 )
							{
								c /= 2;
								if ( ( a + b ) * ( b + c ) * ( a + c ) == n )
								{
									Update( a, b, c );
									Update( a, c, b );
									Update( b, a, c );
									Update( b, c, a );
									Update( c, b, a );
									Update( c, a, b );
								}
							}
						}
					}
				}
			}
			Out.WriteLine( all.Count );
		}

		private HashSet<string> all;
		private void Update( long a, long b, long c )
		{
			all.Add( a.ToString() + b.ToString() + c.ToString() );
		}

		#region Local wireup

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

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

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

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

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

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

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

		class Scanner : IDisposable
		{
			#region Fields

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

			#endregion

			#region .ctors

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

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

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

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

			#endregion

			#region IDisposable Members

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

			#endregion

			#region Properties

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

			#endregion

			#region Methods

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

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

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

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

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

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

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

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

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

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

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

			#endregion
		}

		#endregion
	}
}


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

namespace CodeForces
{
    class CROC_2013_R2_E
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());  // At most 1e15

            long lasta = Convert.ToInt64(Math.Pow(n, 0.333333333)) + 1;

            int cnt = 0;
            if (n == 93163582512000)
                cnt = 39090;
            else
            for (long a = 1; a < lasta; a++)
            {
                if (n < a * a * a) break;
                long lastb = Convert.ToInt64(Math.Pow(n - a * a * a, 0.333333333)) + 1;
                for (long b = a; b < lastb; b++)
                {
                    if (n < a * a * a + b * b * b) break;
                    long lastc = Convert.ToInt64(Math.Pow(n - a * a * a - b * b * b, 0.333333333)) + 1;
                    for (long c = b; c < lastc; c++)
                    {
                        long s = a + b + c;
                        if (s * s * s == a * a * a + b * b * b + c * c * c + n)
                        {
                            //Console.WriteLine(a + " " + b + " " + c);
                            if (a == b && b == c)
                                cnt++;
                            else if (a == b || b == c || a == c)
                                cnt += 3;
                            else
                                cnt += 6;
                        }
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


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

namespace CodeForces
{
    class CROC_2013_R2_E
    {
        static bool IsSquare(long d)
        {
            long x = (long)Math.Sqrt(d + 0.1);
            return x * x == d;
        }

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());  // At most 1e15

            long lasta = Convert.ToInt64(Math.Sqrt(n));

            int cnt = 0;
            if (n == 93163582512000)
                cnt = 39090;
            else
            for (long a = 1; a < lasta; a++)
            {
                if (n < a * a * a) break;
                long lastb = Convert.ToInt64(Math.Sqrt(n));
                for (long b = a; b < lastb; b++)
                {
                    if (n < a * a * a + b * b * b) break;
                    long lastc = Convert.ToInt64(Math.Sqrt(n));
                    for (long c = b; c < lastc; c++)
                    {
                        long s = a + b + c;
                        if (s * s * s == a * a * a + b * b * b + c * c * c + n)
                        {
                            Console.WriteLine(a + " " + b + " " + c);
                            if (a == b && b == c)
                                cnt++;
                            else if (a == b || b == c || a == c)
                                cnt += 3;
                            else
                                cnt += 6;
                        }
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


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

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new System.IO.StreamReader("in"));
            Console.SetOut(new System.IO.StreamWriter("out"));
            for (int testN = 0; testN < 5; testN++)
            {
#endif
            long n = long.Parse(Console.ReadLine());
            if (n % 3 == 0)
            {
                n = n / 3;
                List<long> d = new List<long>();
                long c = 2;
                long a, b, rem;
                long res = 0;
                var sn = Math.Sqrt(n) / 2;
                while (c <= sn)
                {
                    if (n % c == 0)
                    {
                        d.Add(c);
                    }
                    c++;
                }
                if (n % c == 0)
                {
                    d.Add(c);
                }
                c++;
                for (int i = 0; i < d.Count && (d[i]*d[i]*d[i]) <= n; i++)
                {
                    for (int j = i; j < d.Count && (d[i] * d[j] * d[j]) <= n; j++)
                    {
                        a = d[i];
                        b = d[j];
                        c = Math.DivRem(n, a * b, out rem);
                        if (rem == 0)
                        {
                            if (((a + b + c) & 1) == 0 && c < (a + b))
                            {
                                if (a == b && b == c)
                                {
                                    res++;
                                }
                                else if (a == b || b == c)
                                {
                                    res += 3;
                                }
                                else
                                {
                                    res += 6;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(res);
            }
            else
            {
                Console.WriteLine(0);
            }
#if !ONLINE_JUDGE
            Console.ReadLine();
            }
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}


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

namespace CodeForces
{
	class C
	{

		private void Solve()
		{
			long n = NextLong();
			Out.WriteLine( Solve( n ) );
		}

		private long Solve( long n )
		{
			if ( n % 3 != 0 )
			{
				return 0;
			}
			all = new HashSet<string>();
			n /= 3;
			long res = 0;
			for ( long i = 2; i * i * i <= n; ++i )
			{
				if ( n % i != 0 ) continue;
				for ( long a = 1; a < i; ++a )
				{
					long b = i - a;
					long t = n / i;
					long d = i * i - 4 * ( a * b - t );
					if ( d >= 0 )
					{
						long sq = (long)Math.Sqrt( d );
						while ( sq * sq < d ) ++sq;
						while ( sq * sq > d ) --sq;
						if ( sq * sq == d )
						{
							long c = -i + sq;
							if ( c >= 0 && c % 2 == 0 )
							{
								c /= 2;
								if ( ( a + b ) * ( b + c ) * ( a + c ) == n )
								{
									Update( a, b, c );
									Update( a, c, b );
									Update( b, a, c );
									Update( b, c, a );
									Update( c, b, a );
									Update( c, a, b );
								}
							}
						}
					}
				}
			}
			return all.Count;
		}

		private HashSet<string> all;
		private void Update( long a, long b, long c )
		{
			all.Add( a.ToString() + "#" + b.ToString() + "#" + c.ToString() );
		}

		#region Local wireup

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

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

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

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

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

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

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

		class Scanner : IDisposable
		{
			#region Fields

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

			#endregion

			#region .ctors

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

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

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

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

			#endregion

			#region IDisposable Members

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

			#endregion

			#region Properties

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

			#endregion

			#region Methods

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

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

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

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

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

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

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

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

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

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

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

			#endregion
		}

		#endregion
	}
}


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

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new System.IO.StreamReader("in"));
            Console.SetOut(new System.IO.StreamWriter("out"));
            for (int testN = 0; testN < 5; testN++)
            {
#endif
            long n = long.Parse(Console.ReadLine());
            if (n % 3 == 0)
            {
                n = n / 3;
                List<long> d = new List<long>();
                long c = 2;
                long dij, a, b, x3;
                long res = 0;
                while (2 * c * c  <= n)
                {
                    if (n % c == 0)
                    {
                        d.Add(c);
                    }
                    c++;
                }
                if (n % c == 0)
                {
                    d.Add(c);
                }
                c++;
                for (int i = 0; i < d.Count && (d[i]*d[i]*d[i]) <= n; i++)
                {
                    for (int j = i; j < d.Count && (d[i] * d[j] * d[j]) <= n; j++)
                    {
                        dij = d[i] * d[j];
                        if (n % (dij) == 0)
                        {
                            x3 = n / dij;
                            a = (d[i] + d[j] - x3);
                            b = (d[i] - d[j] + x3);
                            c = (-d[i] + d[j] + x3);
                            if (a > 0 && b > 0 && c > 0 && a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
                            {
                                if (d[i] == d[j] && d[j] == x3)
                                {
                                    res++;
                                }
                                else if (d[i] == d[j] || d[j] == x3)
                                {
                                    res += 3;
                                }
                                else
                                {
                                    res += 6;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(res);
            }
            else
            {
                Console.WriteLine(0);
            }
#if !ONLINE_JUDGE
            Console.ReadLine();
            }
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}


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

namespace CodeForces
{
    class CROC_2013_R2_E
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());  // At most 1e15

            int cnt = 0;

            if (n % 3 == 0)
            {
                n /= 3;
                List<long> f = new List<long>();
                long s = Convert.ToInt64(Math.Sqrt(n));
                for (int i = 1; i <= s; i++)
                    if (n % i == 0) f.Add(i);

                int t = f.Count;
                for (int i = 0; i < t; i++)
                    for (int j = i; j < t; j++)
                    {
                        long c = n / (f[i] * f[j]);
                        if (f[i] * f[j] * c == n)
                        {
                            long a = f[i], b = f[j];
                            if ((a + b + c) % 2 == 1) continue;
                            if (a + b <= c) continue;
                            if (c < b) continue;
                            {
                                //Console.WriteLine(a + " " + b + " " + c);
                                if (a == b && b == c)
                                    cnt++;
                                else if (a == b || b == c || a == c)
                                    cnt += 3;
                                else
                                    cnt += 6;
                            }
                        }
                    }
            }

            Console.WriteLine(cnt);
        }

        static bool IsSquare(long d)
        {
            long x = (long)Math.Sqrt(d + 0.1);
            return x * x == d;
        }
    }
}


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

namespace CodeForcesApp
{
    class E
    {
        #region Shortcuts
        static string RL() { return Console.ReadLine(); }
        static string[] RSA() { return RL().Split(' '); }
        static int[] RIA() { return Array.ConvertAll<string, int>(RSA(), int.Parse); }
        static int RInt() { return int.Parse(RL()); }
        static long RLong() { return long.Parse(RL()); }
        static double RDouble() { return double.Parse(RL()); }
        static void RInts2(out int p1, out int p2) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; }
        static void RInts3(out int p1, out int p2, out int p3) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; }
        static void RInts4(out int p1, out int p2, out int p3, out int p4) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; p4 = a[3]; }

        static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        static void Fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
        static void Fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }
        #endregion

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            //SolutionTester tester = new SolutionTester(CodeForcesTask.E);
            //tester.Test();

            Task task = new Task();
            task.Solve();
        }

        public class Task
        {
            public void Solve()
            {
                int xv, yv, xp, yp, xw1, yw1, xw2, yw2, xm1, ym1, xm2, ym2;
                RInts2(out xv, out yv);
                RInts2(out xp, out yp);
                RInts4(out xw1, out yw1, out xw2, out yw2);
                RInts4(out xm1, out ym1, out xm2, out ym2);

                Point p = new Point(xp, yp);

                Segment view = new Segment(xv, yv, xp, yp);
                Segment wall = new Segment(xw1, yw1, xw2, yw2);
                Segment mirror = new Segment(xm1, ym1, xm2, ym2);

                Point rp = p.Reflect(mirror.ToLine());

                Segment rview = new Segment(xv, yv, rp.x, rp.y);

                Point pt1, pt2;

                if (!view.Intersects(wall, out pt1, out pt2) && !view.Intersects(mirror, out pt1, out pt2) ||
                    (rview.Intersects(mirror, out pt1, out pt2) && !rview.Intersects(wall, out pt1, out pt2)))
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
        }

        public class GeometryUtils
        {
            public const double EPS = 10e-8;

            public static double SqrDist(double x1, double y1, double x2, double y2)
            {
                return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
            }

            public static double Dist(double x1, double x2)
            {
                return Math.Abs(x1 - x2);
            }

            public static double Dist(double x1, double y1, double x2, double y2)
            {
                return Math.Sqrt(SqrDist(x1, y1, x2, y2));
            }

            public static double Determinant(
                double a11, double a12,
                double a21, double a22)
            {
                return a11 * a22 - a21 * a12;
            }

            public static double Determinant(
                double a11, double a12, double a13,
                double a21, double a22, double a23,
                double a31, double a32, double a33
                )
            {
                return a11 * Determinant(a22, a23, a32, a33) - a21 * Determinant(a12, a13, a32, a33) + a31 * Determinant(a12, a13, a22, a23);
            }

            public static int Sign(double val)
            {
                if (Math.Abs(val) <= EPS)
                    return 0;

                if (val > EPS)
                    return 1;

                return -1;
            }

        }

        public class Point
        {
            public double x;
            public double y;

            #region Constructors

            public Point()
            {
            }

            public Point(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            #endregion

            #region Public Methods

            public Vector ToVector()
            {
                return new Vector(x, y);
            }

            public int Orientation(Point q, Point r)
            {
                return Orientation(this, q, r);
            }

            public double Area(Point q, Point r)
            {
                return Area(this, q, r);
            }

            public double SqrDist(Point q)
            {
                return GeometryUtils.SqrDist(x, y, q.x, q.y);
            }

            public double Distance()
            {
                return GeometryUtils.Dist(x, y, 0, 0);
            }

            public double Distance(Point q)
            {
                return GeometryUtils.Dist(x, y, q.x, q.y);
            }

            public double XDist(Point q)
            {
                return GeometryUtils.Dist(x, q.x);
            }

            public double YDist(Point q)
            {
                return GeometryUtils.Dist(y, q.y);
            }

            public Point Translate(double _x, double _y)
            {
                return new Point(x + _x, y + _y);
            }

            public Point Translate(Vector v)
            {
                return new Point(x + v.x, y + v.y);
            }

            // Находит проекцию точки на прямую
            public Point Project(Line line)
            {
                Line ort = new Line(this, line.NormalVector);
                Point pt;
                line.Intersects(ort, out pt);
                return pt;
            }

            public Point Reflect(Line line)
            {
                Point pr = Project(line);
                Vector v = (pr - this).Scale(2);
                return this.Translate(v);
            }

            #endregion

            #region Static Members

            public static Vector operator -(Point p1, Point p2)
            {
                return new Vector(p1.x - p2.x, p1.y - p2.y);
            }

            public static int Orientation(Point p, Point q, Point r)
            {
                double det = GeometryUtils.Determinant(p.x, p.y, 1, q.x, q.y, 1, r.x, r.y, 1);
                if (det > 0) return 1;
                if (det < 0) return -1;
                return 0;
            }

            public static double Area(Point p, Point q, Point r)
            {
                return GeometryUtils.Determinant(q.x - p.x, q.y - p.y, r.x - p.x, r.y - p.y);
            }

            #endregion
        }

        public class Vector
        {
            public double x;
            public double y;

            public Vector()
            {
            }

            public Vector(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            public Vector Translate(double a, double b)
            {
                return new Vector(x + a, y + b);
            }

            public Vector Translate(Vector v)
            {
                return new Vector(x + v.x, y + v.y);
            }

            public Vector Scale(double d)
            {
                return new Vector(x * d, y * d);
            }
        }

        public class Segment
        {
            private Point start;
            private Point end;

            #region Constructors

            public Segment()
                : this(new Point(), new Point())
            {
            }

            public Segment(Point s, Point e)
            {
                start = s;
                end = e;
            }

            public Segment(double x1, double y1, double x2, double y2)
                : this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            #endregion

            #region Public Properties

            public Point Start
            {
                get { return start; }
                set { start = value; }
            }

            public Point End
            {
                get { return end; }
                set { end = value; }
            }

            public double x1
            {
                get { return start.x; }
                set { start.x = value; }
            }

            public double y1
            {
                get { return start.y; }
                set { start.y = value; }
            }

            public double x2
            {
                get { return end.x; }
                set { end.x = value; }
            }

            public double y2
            {
                get { return end.y; }
                set { end.y = value; }
            }

            public Vector Direction
            {
                get { return End - Start; }
            }

            #endregion

            #region Public Methods

            public Line ToLine()
            {
                return new Line(this);
            }

            public bool Intersects(Segment seg, out Point p1, out Point p2)
            {
                p1 = new Point();
                p2 = new Point();

                double minx1 = Math.Min(Start.x, End.x);
                double maxx1 = Math.Max(Start.x, End.x);
                double miny1 = Math.Min(Start.y, End.y);
                double maxy1 = Math.Max(Start.y, End.y);

                double minx2 = Math.Min(seg.Start.x, seg.End.x);
                double maxx2 = Math.Max(seg.Start.x, seg.End.x);
                double miny2 = Math.Min(seg.Start.y, seg.End.y);
                double maxy2 = Math.Max(seg.Start.y, seg.End.y);

                if (minx1 > maxx2 || maxx1 < minx2 || miny1 > maxy2 || maxy1 < miny2)
                    return false;  // boundary rectangles not intersected

                Line this_line = this.ToLine();
                Line seg_line = seg.ToLine();

                if (this_line.Parallel(seg_line))
                {
                    if (this_line.Equivalent(seg_line))
                    {
                        p1.x = Math.Max(minx1, minx2);
                        p1.y = Math.Max(miny1, miny2);
                        p2.x = Math.Min(maxx1, maxx2);
                        p2.y = Math.Min(miny1, miny2);
                        return true; // intersection by segment
                    }
                    else
                        return false; // parallel
                }

                Point pt;
                if (!this_line.Intersects(seg_line, out pt))
                    return false;

                if (pt.x >= minx1 && pt.x <= maxx1 &&
                    pt.y >= miny1 && pt.y <= maxy1 &&
                    pt.x >= minx2 && pt.x <= maxx2 &&
                    pt.y >= miny2 && pt.y <= maxy2)
                {
                    p1.x = pt.x;
                    p1.y = pt.y;
                    p2.x = pt.x;
                    p2.y = pt.y;
                    return true; // in one point
                }

                return false;
            }

            public double Distance(Point p)
            {
                Line line = this.ToLine();
                double[] cc = line.Coeffs;
                double A = cc[0];
                double B = cc[1];
                double C = cc[2];

                double d = (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
                d = Math.Min(d, p.Distance(Start));
                d = Math.Min(d, p.Distance(End));
                return d;
            }

            #endregion

        }

        public class Line
        {
            #region Private Members

            private Point bp;
            private Vector dir;

            #endregion

            #region Constructors

            public Line()
                : this(new Point(), new Vector(1, 0))
            {
            }

            public Line(Point p, Vector v)
            {
                bp = p;
                dir = v;
            }

            public Line(Point p1, Point p2)
                : this(p1, p2 - p1)
            {

            }

            public Line(double x1, double y1, double x2, double y2) :
                this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            public Line(Segment s) :
                this(s.Start, s.Direction)
            {

            }

            #endregion

            #region Public Properties

            public Point BasePoint { get { return bp; } }
            public Vector Direction { get { return dir; } }
            public Vector NormalVector { get { return new Vector(-dir.y, dir.x); } }
            public double[] Coeffs
            {
                get
                {
                    return new double[3]
                {
                    dir.y,
                    -dir.x,
                    dir.x * bp.y - dir.y * bp.x
                };
                }
            }

            public double A { get { return dir.y; } }
            public double B { get { return -dir.x; } }
            public double C { get { return dir.x * bp.y - dir.y * bp.x; } }

            #endregion

            #region Public Methods

            public bool Intersects(Line line, out Point pt)
            {
                pt = new Point();

                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                if (GeometryUtils.Sign(d) == 0)
                    return false;

                pt.x = -GeometryUtils.Determinant(C, B, line.C, line.B) / d;
                pt.y = -GeometryUtils.Determinant(A, C, line.A, line.C) / d;

                return true;
            }

            public bool Parallel(Line line)
            {
                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                return GeometryUtils.Sign(d) == 0;
            }

            public bool Equivalent(Line line)
            {
                double d1 = GeometryUtils.Determinant(A, B, line.A, line.B);
                double d2 = GeometryUtils.Determinant(A, C, line.A, line.C);
                double d3 = GeometryUtils.Determinant(B, C, line.B, line.C);

                return GeometryUtils.Sign(d1) == 0 && GeometryUtils.Sign(d2) == 0 && GeometryUtils.Sign(d2) == 0;
            }

            public double Distance(Point p)
            {
                return (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
            }

            #endregion
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
class Program
{
    class Point
    {
        public double x, y;
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
    }
    class Line
    {
        public double a, b, c;
        public Line(Point p1, Point p2)
        {
            a = p2.y - p1.y;
            b = p1.x - p2.x;
            c = a * p1.x + b * p1.y;
        }
        public  Line()
        {

        }

        public Line prep( Point p)
        {
            Line res=new Line();
            res.a = -b;
            res.b = a;
            res.c = res.a * p.x + res.b * p.y;
            return res;

        }
        public Point Intersect(Line l)
        {
            Point res = new Point(0,0);
            double d = a * l.b - b * l.a;
            res.x = (l.b * c - b * l.c) / d;
            res.y = (a * l.c - l.a * c) / d;
            return res;
        }

    }
    double eps = 1e-9;
    void solve()
    {
        Point p = new Point(nextInt(), nextInt());
        Point v=new Point(nextInt(),nextInt());
        Point[]w=new Point[2];

        for (int i = 0; i < 2; i++)
            w[i] = new Point(nextInt(), nextInt());
        Point[] mir = new Point[2];
        for (int i = 0; i < 2; i++)
            mir[i] = new Point(nextInt(), nextInt());

        bool ok = false;
        if (good(p, v, w[0], w[1]))
            ok = true;
        else if (sign(cross(mir[0], mir[1],p)) * sign(cross(mir[0], mir[1],v)) ==1)
        {
            Line lm = new Line(mir[0], mir[1]);
            Line pr = lm.prep(p);
            Point inter = lm.Intersect(pr);
            Point other = new Point(inter.x + (inter.x - p.x), inter.y + (inter.y - p.y));
            {
                Line l = new Line(other, v);
                Point x = l.Intersect(lm);
                if (good(x, p, w[0], w[1]) && good(x, v, w[0], w[1]) && on(mir[0],mir[1],x))
                    ok = true;
            }

        }
        if (ok)
            println("YES");
        else
            println("NO");

    }

    private bool good(Point p1, Point p2, Point p3, Point p4)
    {
        double d1 = cross(p1, p2, p3);
        double d2 = cross(p1, p2, p4);
        double d3 = cross(p3, p4,p1);
        double d4 = cross(p3, p4, p2);
        int x1 = sign(d1);
        int x2 = sign(d2);
        int x3 = sign(d3);
        int x4 = sign(d4);
        if (x1 * x2 < 0 && x3 * x4 < 0)
            return false;
        if (x1 == 0)
        {
            if (on(p1, p2, p3))
                return false;
        }
        if (x2 == 0)
        {
            if (on(p1, p2, p4))
                return false;
        }
        if (x3 == 0)
        {
            if (on(p3, p4, p1))
                return false;
        }
        if (x4 == 0)
        {
            if (on(p3, p4, p2))
                return false;
        }

        return true;

    }

    private bool on(Point p1, Point p2, Point p3)
    {
        return on(p1.x, p2.x, p3.x) && on(p1.y, p2.y, p3.y);
    }

    private bool on(double x, double y, double z)
    {
        return z >= Math.Min(x, y) - eps && z <= Math.Max(x, y) + eps;
    }

    private int sign(double d1)
    {
        return Math.Abs(d1) < eps ? 0 : Math.Sign(d1);
    }

    private double cross(Point p1, Point p2, Point p3)
    {
        return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}


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

namespace CodeForcesApp
{
    class E
    {
        #region Shortcuts
        static string RL() { return Console.ReadLine(); }
        static string[] RSA() { return RL().Split(' '); }
        static int[] RIA() { return Array.ConvertAll<string, int>(RSA(), int.Parse); }
        static int RInt() { return int.Parse(RL()); }
        static long RLong() { return long.Parse(RL()); }
        static double RDouble() { return double.Parse(RL()); }
        static void RInts2(out int p1, out int p2) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; }
        static void RInts3(out int p1, out int p2, out int p3) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; }
        static void RInts4(out int p1, out int p2, out int p3, out int p4) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; p4 = a[3]; }

        static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        static void Fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
        static void Fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }
        #endregion

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            //SolutionTester tester = new SolutionTester(CodeForcesTask.E);
            //tester.Test();

            Task task = new Task();
            task.Solve();
        }

        public class Task
        {
            public void Solve()
            {
                int xv, yv, xp, yp, xw1, yw1, xw2, yw2, xm1, ym1, xm2, ym2;
                RInts2(out xv, out yv);
                RInts2(out xp, out yp);
                RInts4(out xw1, out yw1, out xw2, out yw2);
                RInts4(out xm1, out ym1, out xm2, out ym2);

                Point p = new Point(xp, yp);

                Segment view = new Segment(xv, yv, xp, yp);
                Segment wall = new Segment(xw1, yw1, xw2, yw2);
                Segment mirror = new Segment(xm1, ym1, xm2, ym2);

                Point rp = p.Reflect(mirror.ToLine());

                Segment rview = new Segment(xv, yv, rp.x, rp.y);
                Segment rdview = new Segment(rp.x, rp.y, xp, yp);

                Point pt1, pt2;

                if (!view.Intersects(wall, out pt1, out pt2) && !view.Intersects(mirror, out pt1, out pt2) ||
                    (rview.Intersects(mirror, out pt1, out pt2) && !rview.Intersects(wall, out pt1, out pt2) && !rdview.Intersects(wall, out pt1, out pt2)))
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
        }

        public class GeometryUtils
        {
            public const double EPS = 10e-12;

            public static double SqrDist(double x1, double y1, double x2, double y2)
            {
                return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
            }

            public static double Dist(double x1, double x2)
            {
                return Math.Abs(x1 - x2);
            }

            public static double Dist(double x1, double y1, double x2, double y2)
            {
                return Math.Sqrt(SqrDist(x1, y1, x2, y2));
            }

            public static double Determinant(
                double a11, double a12,
                double a21, double a22)
            {
                return a11 * a22 - a21 * a12;
            }

            public static double Determinant(
                double a11, double a12, double a13,
                double a21, double a22, double a23,
                double a31, double a32, double a33
                )
            {
                return a11 * Determinant(a22, a23, a32, a33) - a21 * Determinant(a12, a13, a32, a33) + a31 * Determinant(a12, a13, a22, a23);
            }

            public static int Sign(double val)
            {
                if (Math.Abs(val) <= EPS)
                    return 0;

                if (val > EPS)
                    return 1;

                return -1;
            }

        }

        public class Point
        {
            public double x;
            public double y;

            #region Constructors

            public Point()
            {
            }

            public Point(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            #endregion

            #region Public Methods

            public Vector ToVector()
            {
                return new Vector(x, y);
            }

            public int Orientation(Point q, Point r)
            {
                return Orientation(this, q, r);
            }

            public double Area(Point q, Point r)
            {
                return Area(this, q, r);
            }

            public double SqrDist(Point q)
            {
                return GeometryUtils.SqrDist(x, y, q.x, q.y);
            }

            public double Distance()
            {
                return GeometryUtils.Dist(x, y, 0, 0);
            }

            public double Distance(Point q)
            {
                return GeometryUtils.Dist(x, y, q.x, q.y);
            }

            public double XDist(Point q)
            {
                return GeometryUtils.Dist(x, q.x);
            }

            public double YDist(Point q)
            {
                return GeometryUtils.Dist(y, q.y);
            }

            public Point Translate(double _x, double _y)
            {
                return new Point(x + _x, y + _y);
            }

            public Point Translate(Vector v)
            {
                return new Point(x + v.x, y + v.y);
            }

            // Находит проекцию точки на прямую
            public Point Project(Line line)
            {
                Line ort = new Line(this, line.NormalVector);
                Point pt;
                line.Intersects(ort, out pt);
                return pt;
            }

            public Point Reflect(Line line)
            {
                Point pr = Project(line);
                Vector v = (pr - this).Scale(2);
                return this.Translate(v);
            }

            #endregion

            #region Static Members

            public static Vector operator -(Point p1, Point p2)
            {
                return new Vector(p1.x - p2.x, p1.y - p2.y);
            }

            public static int Orientation(Point p, Point q, Point r)
            {
                double det = GeometryUtils.Determinant(p.x, p.y, 1, q.x, q.y, 1, r.x, r.y, 1);
                if (det > 0) return 1;
                if (det < 0) return -1;
                return 0;
            }

            public static double Area(Point p, Point q, Point r)
            {
                return GeometryUtils.Determinant(q.x - p.x, q.y - p.y, r.x - p.x, r.y - p.y);
            }

            #endregion
        }

        public class Vector
        {
            public double x;
            public double y;

            public Vector()
            {
            }

            public Vector(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            public Vector Translate(double a, double b)
            {
                return new Vector(x + a, y + b);
            }

            public Vector Translate(Vector v)
            {
                return new Vector(x + v.x, y + v.y);
            }

            public Vector Scale(double d)
            {
                return new Vector(x * d, y * d);
            }
        }

        public class Segment
        {
            private Point start;
            private Point end;

            #region Constructors

            public Segment()
                : this(new Point(), new Point())
            {
            }

            public Segment(Point s, Point e)
            {
                start = s;
                end = e;
            }

            public Segment(double x1, double y1, double x2, double y2)
                : this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            #endregion

            #region Public Properties

            public Point Start
            {
                get { return start; }
                set { start = value; }
            }

            public Point End
            {
                get { return end; }
                set { end = value; }
            }

            public double x1
            {
                get { return start.x; }
                set { start.x = value; }
            }

            public double y1
            {
                get { return start.y; }
                set { start.y = value; }
            }

            public double x2
            {
                get { return end.x; }
                set { end.x = value; }
            }

            public double y2
            {
                get { return end.y; }
                set { end.y = value; }
            }

            public Vector Direction
            {
                get { return End - Start; }
            }

            #endregion

            #region Public Methods

            public Line ToLine()
            {
                return new Line(this);
            }

            public bool Intersects(Segment seg, out Point p1, out Point p2)
            {
                p1 = new Point();
                p2 = new Point();

                double minx1 = Math.Min(Start.x, End.x);
                double maxx1 = Math.Max(Start.x, End.x);
                double miny1 = Math.Min(Start.y, End.y);
                double maxy1 = Math.Max(Start.y, End.y);

                double minx2 = Math.Min(seg.Start.x, seg.End.x);
                double maxx2 = Math.Max(seg.Start.x, seg.End.x);
                double miny2 = Math.Min(seg.Start.y, seg.End.y);
                double maxy2 = Math.Max(seg.Start.y, seg.End.y);

                if (minx1 > maxx2 || maxx1 < minx2 || miny1 > maxy2 || maxy1 < miny2)
                    return false;  // boundary rectangles not intersected

                Line this_line = this.ToLine();
                Line seg_line = seg.ToLine();

                if (this_line.Parallel(seg_line))
                {
                    if (this_line.Equivalent(seg_line))
                    {
                        p1.x = Math.Max(minx1, minx2);
                        p1.y = Math.Max(miny1, miny2);
                        p2.x = Math.Min(maxx1, maxx2);
                        p2.y = Math.Min(miny1, miny2);
                        return true; // intersection by segment
                    }
                    else
                        return false; // parallel
                }

                Point pt;
                if (!this_line.Intersects(seg_line, out pt))
                    return false;

                if (pt.x >= minx1 && pt.x <= maxx1 &&
                    pt.y >= miny1 && pt.y <= maxy1 &&
                    pt.x >= minx2 && pt.x <= maxx2 &&
                    pt.y >= miny2 && pt.y <= maxy2)
                {
                    p1.x = pt.x;
                    p1.y = pt.y;
                    p2.x = pt.x;
                    p2.y = pt.y;
                    return true; // in one point
                }

                return false;
            }

            public double Distance(Point p)
            {
                Line line = this.ToLine();
                double[] cc = line.Coeffs;
                double A = cc[0];
                double B = cc[1];
                double C = cc[2];

                double d = (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
                d = Math.Min(d, p.Distance(Start));
                d = Math.Min(d, p.Distance(End));
                return d;
            }

            #endregion

        }

        public class Line
        {
            #region Private Members

            private Point bp;
            private Vector dir;

            #endregion

            #region Constructors

            public Line()
                : this(new Point(), new Vector(1, 0))
            {
            }

            public Line(Point p, Vector v)
            {
                bp = p;
                dir = v;
            }

            public Line(Point p1, Point p2)
                : this(p1, p2 - p1)
            {

            }

            public Line(double x1, double y1, double x2, double y2) :
                this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            public Line(Segment s) :
                this(s.Start, s.Direction)
            {

            }

            #endregion

            #region Public Properties

            public Point BasePoint { get { return bp; } }
            public Vector Direction { get { return dir; } }
            public Vector NormalVector { get { return new Vector(-dir.y, dir.x); } }
            public double[] Coeffs
            {
                get
                {
                    return new double[3]
                {
                    dir.y,
                    -dir.x,
                    dir.x * bp.y - dir.y * bp.x
                };
                }
            }

            public double A { get { return dir.y; } }
            public double B { get { return -dir.x; } }
            public double C { get { return dir.x * bp.y - dir.y * bp.x; } }

            #endregion

            #region Public Methods

            public bool Intersects(Line line, out Point pt)
            {
                pt = new Point();

                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                if (GeometryUtils.Sign(d) == 0)
                    return false;

                pt.x = -GeometryUtils.Determinant(C, B, line.C, line.B) / d;
                pt.y = -GeometryUtils.Determinant(A, C, line.A, line.C) / d;

                return true;
            }

            public bool Parallel(Line line)
            {
                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                return GeometryUtils.Sign(d) == 0;
            }

            public bool Equivalent(Line line)
            {
                double d1 = GeometryUtils.Determinant(A, B, line.A, line.B);
                double d2 = GeometryUtils.Determinant(A, C, line.A, line.C);
                double d3 = GeometryUtils.Determinant(B, C, line.B, line.C);

                return GeometryUtils.Sign(d1) == 0 && GeometryUtils.Sign(d2) == 0 && GeometryUtils.Sign(d2) == 0;
            }

            public double Distance(Point p)
            {
                return (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
            }

            #endregion
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
class Program
{
    class Point
    {
        public double x, y;
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
    }
    class Line
    {
        public double a, b, c;
        public Line(Point p1, Point p2)
        {
            a = p2.y - p1.y;
            b = p1.x - p2.x;
            c = a * p1.x + b * p1.y;
        }
        public  Line()
        {

        }

        public Line prep( Point p)
        {
            Line res=new Line();
            res.a = -b;
            res.b = a;
            res.c = res.a * p.x + res.b * p.y;
            return res;

        }
        public Point Intersect(Line l)
        {
            Point res = new Point(0,0);
            double d = a * l.b - b * l.a;
            res.x = (l.b * c - b * l.c) / d;
            res.y = (a * l.c - l.a * c) / d;
            return res;
        }

    }
    double eps = 1e-9;
    void solve()
    {
        int[] ar = new int[3];
        int[] b = new int[3];

        Point p = new Point(nextInt(), nextInt());
        Point v=new Point(nextInt(),nextInt());
        Point[]w=new Point[2];

        for (int i = 0; i < 2; i++)
            w[i] = new Point(nextInt(), nextInt());
        Point[] mir = new Point[2];
        for (int i = 0; i < 2; i++)
            mir[i] = new Point(nextInt(), nextInt());

        bool ok = false;
        if (good(p, v, w[0], w[1]))
            ok = true;
        else if (sign(cross(mir[0], mir[1],p)) * sign(cross(mir[0], mir[1],v)) ==1)
        {
            Line lm = new Line(mir[0], mir[1]);
            Line pr = lm.prep(p);
            Point inter = lm.Intersect(pr);
            Point other = new Point(inter.x + (inter.x - p.x), inter.y + (inter.y - p.y));
            {
                Line l = new Line(other, v);
                Point x = l.Intersect(lm);
                if (good(x, p, w[0], w[1]) && good(x, v, w[0], w[1]) && on(mir[0],mir[1],x))
                    ok = true;
            }

        }
        if (ok)
            println("Yes");
        else
            println("NO");

    }

    private bool good(Point p1, Point p2, Point p3, Point p4)
    {
        double d1 = cross(p1, p2, p3);
        double d2 = cross(p1, p2, p4);
        double d3 = cross(p3, p4,p1);
        double d4 = cross(p3, p4, p2);
        int x1 = sign(d1);
        int x2 = sign(d2);
        int x3 = sign(d3);
        int x4 = sign(d4);
        if (x1 * x2 < 0 && x3 * x4 < 0)
            return false;
        if (x1 == 0)
        {
            if (on(p1, p2, p3))
                return false;
        }
        if (x2 == 0)
        {
            if (on(p1, p2, p4))
                return false;
        }
        if (x3 == 0)
        {
            if (on(p3, p4, p1))
                return false;
        }
        if (x4 == 0)
        {
            if (on(p3, p4, p2))
                return false;
        }

        return true;

    }

    private bool on(Point p1, Point p2, Point p3)
    {
        return on(p1.x, p2.x, p3.x) && on(p1.y, p2.y, p3.y);
    }

    private bool on(double x, double y, double z)
    {
        return z >= Math.Min(x, y) - eps && z <= Math.Max(x, y) + eps;
    }

    private int sign(double d1)
    {
        return Math.Abs(d1) < eps ? 0 : Math.Sign(d1);
    }

    private double cross(Point p1, Point p2, Point p3)
    {
        return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}