#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   if(x<k&&low<high)
   {
       mid = (low + high) / 2;
      for(int i=low,j=mid;i<j;i++,j--)
      {
          int temp=a[i];
          a[i]=a[j];
          a[j]=temp;
       }
       k-=4;
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            unsort(a,0,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=4;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>

int arr[100001] ;

int n , k , total = 1 ;

void reverseMerge( int start , int end ){

    if( total == k || start + 1 == end ) return ;

    int mid = ( end + start ) / 2 ;

    if( mid - 1 < start ) return ;

    int temp = arr[mid] ;

    arr[mid] = arr[mid - 1] ;

    arr[mid - 1] = temp ;

    total += 2 ;

    reverseMerge( start , mid ) ;

    reverseMerge( mid , end ) ;
}

void solve(){

    scanf("%d %d",&n,&k) ;

    if( k % 2 == 0  ){

        printf("-1\n") ;

        return ;
    }

    for( int i = 0 ; i < n ; i++ )

        arr[i] = i + 1 ;

    reverseMerge( 0 , n ) ;

    if( total != k ){

        printf("-1") ;

        return ;
    }

    for( int i = 0 ; i < n ; i++ ) printf("%d ",arr[i]) ;
}

int main(){

    solve() ;

    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=8;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k/=2;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   if(x<k&&low<high)
   {
       mid = (low + high) / 2;
      for(int i=low,j=mid;i<j;i++,j--)
      {
          int temp=a[i];
          a[i]=a[j];
          a[j]=temp;
       }
       k-=2;
      unsort(a,low, mid,k);
      unsort(a,mid+1, high,k);
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            unsort(a,0,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=20;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>

void MergeSort(int* arr, int p, int r, int* k_count, int k)
{
	if(p<r && (*k_count)<k)
	{
		int q, n = r-p+1;
		q=p+(n/2);

		for(int i=p;i<=q-1;i++)
		{
			int temp = arr[i+q-p];
			arr[i+q-p] = arr[i];
			arr[i] = temp;
		}

		(*k_count) = (*k_count) + 2;
		MergeSort(arr,p,q-1,k_count,k);
		MergeSort(arr,q,r,k_count,k);

	}
}

int main()
{
	int n,k,k_max,s,s_max,i,j;
	scanf("%d %d",&n,&k);

	k_max = 2*n-1;
	s_max = n-1;
	s = (k-1)/2;

	int arr[n];
	for(i=0;i<n;i++)	arr[i] = i+1;

	if(k%2==0 || k>k_max)	printf("-1");
	else
	{
		int* k_count = (int *)malloc(sizeof(int));
		(*k_count) = 1;
		MergeSort(arr,0,n-1,k_count,k);

		printf("\n");
		for(j=0;j<n;j++)	printf("%d  ",arr[j]);
		printf("\n");
	}

	return 0;
}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = data[0];
            int k = data[1];
            if (k % 2 == 0 || k > 2 * n - 1)
            {
                Console.WriteLine(-1);
                return;
            }

            int[] ans = Enumerable.Range(1, n).ToArray();
            Action<int, int> Swap = (first, second) =>
            {
                int tmp = ans[first];
                ans[first] = ans[second];
                ans[second] = tmp;
            };

            Action<int, int> UnSort = null;
            UnSort = (low, high) =>
            {
                if (low + 1 == high || k <= 1) return;
                int mid = low + high >> 1;
                k -= 2;
                Swap(mid - 1, mid);
                UnSort(low, mid);
                UnSort(mid, high);
            };

            UnSort(0, n);
            ;
            ans.ToList().ForEach(c => Console.Write(c + " "));

        }
    }

}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = data[0];
            int k = data[1];
            if (k % 2 == 0 || k > 2 * n - 1)
            {
                Console.WriteLine(-1);
                return;
            }

            int[] ans = Enumerable.Range(1, n).ToArray();
            Action<int, int> Swap = (first, second) =>
            {
                int tmp = ans[first];
                ans[first] = ans[second];
                ans[second] = tmp;
            };

            Action<int, int> UnSort = null;
            UnSort = (low, high) =>
            {
                if (low >= high || k <= 1) return;
                int mid = low + high >> 1;
                k -= 2;
                Swap(mid, mid + 1);
                UnSort(low, mid);
                UnSort(mid + 1, high);
            };

            UnSort(0, n - 1);
            StringBuilder res = new StringBuilder();
            ans.ToList().ForEach(c => res.Append(c + " "));
            Console.WriteLine(res);

        }
    }

}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = data[0];
            int k = data[1];
            if (k % 2 == 0 || k > 2 * n - 1)
            {
                Console.WriteLine(-1);
                return;
            }

            int[] ans = Enumerable.Range(1, n).ToArray();
            Action<int, int> Swap = (first, second) =>
            {
                int tmp = ans[first];
                ans[first] = ans[second];
                ans[second] = tmp;
            };

            Action<int, int> UnSort = null;
            UnSort = (low, high) =>
            {
                if (low >= high || k <= 1) return;
                int mid = low + high >> 1;
                k -= 2;
                Swap(mid - 1, mid);
                UnSort(low, mid - 1);
                UnSort(mid, high);
            };

            UnSort(0, n - 1);
            StringBuilder res = new StringBuilder();
            ans.ToList().ForEach(c => res.Append(c + " "));
            Console.WriteLine(res);

        }
    }

}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = data[0];
            int k = data[1];
            if (k % 2 == 0 || k > 2 * n - 1)
            {
                Console.WriteLine(-1);
                return;
            }

            int[] ans = Enumerable.Range(1, n).ToArray();
            Action<int, int> Swap = (first, second) =>
            {
                int tmp = ans[first];
                ans[first] = ans[second];
                ans[second] = tmp;
            };

            Action<int, int> UnSort = null;
            UnSort = (low, high) =>
            {
                if (low + 1 == high || k <= 1) return;
                int mid = low + high >> 1;
                k -= 2;
                Swap(mid - 1, mid);
                UnSort(low, mid);
                UnSort(mid, high);
            };

            UnSort(0, n);
            StringBuilder res = new StringBuilder();
            ans.ToList().ForEach(c => res.Append(c + " "));
            Console.WriteLine(res);

        }
    }

}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N, K;
    int[] Ans;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();

        // マージソート
        // mergesort(a,l,r)再帰

        // 呼び出し回数 k回になるa

        /*
         * 1 1
         * 2 1 3
         * 3 1 3 5
         * 4 1 3 5 7
         * 5 1 3 5 7 9
         */

        // 2n-1以下奇数OK

        if (K > 2 * N - 1)
        {
            Console.WriteLine("-1");
            return;
        }

        if (K % 2 != 1)
        {
            Console.WriteLine("-1");
            return;
        }

        // 分けない 1
        // 分ける 右 + 左 + 1
        Ans = new int[N];
        Calc(0, N, 1, K);

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

    // [begin,end)を最小min,最大 min+(end-begin)-1
    // k回になるようにする
    void Calc(int begin, int end, int min, int k)
    {
        if (k == 1)
        {
            for (int i = 0; i < end - begin; i++)
            {
                Ans[begin + i] = min + i;
            }
            return;
        }

        int mid = (begin + end) / 2;
        int leftLen = mid - begin;
        int leftK = Math.Min(k - 2, leftLen * 2 - 1);
        Calc(begin, mid, min + end - mid, leftK);
        Calc(mid, end, min, k - 1 - leftK);
    }

    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;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        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;
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
{
    int now = 1,N,K,c;
    int[] res, dp;
    public void Solve(Scanner sc)
    {
        sc.Make(out N, out K);
        dp = new int[N + 1];
        dp[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            dp[i] = dp[i / 2] + dp[(i + 1) / 2] + 1;
        }
        if (dp[N] < K || K % 2 == 0) Fail(-1);
        c = dp[N];
        res = new int[N];
        dfs(0, N);
        for (int i = N-1; i>=0;i--)
            if (res[i] == 0) res[i] = now++;
        Console.WriteLine(string.Join(" ", res));
    }
    public void dfs(int l,int r)
    {
        if (r - l == 1) return;
        if (dp[r - l] - 1 <= c-K)
        {
            for (int j = l; j < r; j++)
                res[j] = now++;
            c -= dp[r - l] - 1;
            return;
        }
        dfs((l + r) >> 1, r);
        dfs(l, (l + r) >> 1);
    }
}

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

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

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

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.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
{
    int now = 1,N,K;
    int[] res, dp;
    public void Solve(Scanner sc)
    {
        sc.Make(out N, out K);
        dp = new int[N + 1];
        dp[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            dp[i] = dp[i / 2] + dp[(i + 1) / 2] + 1;
        }
        if (dp[N] < K || K % 2 == 0) Fail(-1);
        res = new int[N];
        dfs(0, N);
        for (int i = 0; i < N; i++)
            if (res[i] == 0) res[i] = now++;
        Console.WriteLine(string.Join(" ", res));
    }
    public void dfs(int l,int r)
    {
        if (r - l == 1) return;
        if (dp[r - l] - 1 < K)
        {
            for (int j = l; j < r; j++)
                res[j] = now++;
            K -= dp[r - l] - 1;
            return;
        }
        dfs(l, (l + r) >> 1);
        dfs((l + r) >> 1, r);
    }
}

#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


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mut mid = (l + r) / 2;
    if (l + r) % 2 == 1 {
        mid += 1;
    }
    for i in mid..r {
        new_piece[i - mid] = array[i];
    }
    for i in l..mid {
        new_piece[i - l + r - mid] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if (l + r) % 2 == 1 {
        mid -= 1;
    }
    if *k > 0 {
        shuffle(array, l, mid, k);
    }
    if *k > 0 {
        shuffle(array, mid, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mid = (l + r) / 2;
    for i in mid..r {
        new_piece[i - mid] = array[i];
    }
    for i in l..mid {
        new_piece[i - l + r - mid] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if *k > 0 {
        shuffle(array, l, mid, k);
    }
    if *k > 0 {
        shuffle(array, mid, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mut mid = (l + r) / 2;
    if (l + r) % 2 == 1 {
        mid += 1;
    }
    for i in mid..r {
        new_piece[i - mid] = array[i];
    }
    for i in l..mid {
        new_piece[i - l + r - mid] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if *k > 0 {
        shuffle(array, l, mid, k);
    }
    if *k > 0 {
        shuffle(array, mid, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mid = (l + r) / 2 + 1;
    for i in mid..r {
        new_piece[i - mid] = array[i];
    }
    for i in l..mid {
        new_piece[i - l + r - mid] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if *k > 0 {
        shuffle(array, l, mid - 1, k);
    }
    if *k > 0 {
        shuffle(array, mid - 1, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mut mid = (l + r) / 2;
    if (l + r) % 2 == 1 {
        mid += 1;
    }
    for i in mid + 1..r {
        new_piece[i - mid - 1] = array[i];
    }
    for i in l..mid + 1 {
        new_piece[i - l + r - mid - 1] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if *k > 0 {
        shuffle(array, l, mid, k);
    }
    if *k > 0 {
        shuffle(array, mid, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;

// k - сколько раз осталось запустить
fn shuffle(array : &mut Vec<usize>, l : usize, r : usize, k : &mut usize) {
    if r == l + 1 {
        return ()
    }

    *k = *k - 2;
    let mut new_piece = vec![0; r - l];
    let mid = (l + r) / 2;
    for i in (mid + 1)..r {
        new_piece[i - mid - 1] = array[i];
    }
    for i in l..(mid + 1) {
        new_piece[i - l + r - mid - 1] = array[i];
    }
    for i in l..r {
        array[i] = new_piece[i - l];
    }

    if *k > 0 {
        shuffle(array, l, mid, k);
    }
    if *k > 0 {
        shuffle(array, mid, r, k);
    }
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nk : Vec<usize>= line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, mut k) : (usize, usize) = (nk[0], nk[1]);
    if k % 2 == 0 {
        print!("-1");
        return ()
    }

    let mut array : Vec<usize> = (1..n + 1).collect();
    let len = array.len();
    if k != 1 {
        k -= 1;
        shuffle(&mut array, 0, len, &mut k);
    }

    if k > 0 && k != 1 {
        print!("-1");
    } else {
        for i in array {
            print!("{} ", i);
        }
    }
}


use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let (n, k): (usize, usize) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    if k % 2 == 0 {
        println!("-1");
        return;
    }

    let mut v: Vec<_> = (0..n).collect();

    let mut reached = false;

    foo(&mut v[..], &mut 1, k, &mut reached);

    if reached {
        for i in v {
            print!("{} ", i + 1);
        }
        println!("");
    } else {
        println!("-1");
    }
}

fn foo(a: &mut[usize], count: &mut usize, target: usize, reached: &mut bool) {
    let mid = a.len() / 2;
    let len = a.len();
    if *count < target {
        a.swap(mid - 1, mid);
        *count += 2;
    }
    if *count < target && mid > 1 {
        foo(&mut a[..mid], count, target, reached);
    }
    if *count < target && len > 2{
        foo(&mut a[mid..], count, target, reached);
    }
    if *count == target {
        *reached = true;
    }
}


use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let (n, k): (usize, usize) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    if k % 2 == 0 {
        println!("-1");
        return;
    }

    let mut v: Vec<_> = (0..n).collect();

    let mut reached = false;

    foo(&mut v[..], 1, k, &mut reached);

    if reached {
        for i in v {
            print!("{} ", i + 1);
        }
        println!("");
    } else {
        println!("-1");
    }
}

fn foo(a: &mut[usize], mut count: usize, target: usize, reached: &mut bool) {
    let mid = a.len() / 2;
    let len = a.len();
    if count < target && mid > 1 {
        a.swap(0, mid - 1);
        count += 2;
        foo(&mut a[..mid], count, target, reached);
    }
    if count < target && len > 2{
        a.swap(mid, len - 1);
        count += 2;
        foo(&mut a[mid..], count, target, reached);
    }
    if count == target {
        *reached = true;
    }
}


use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let (n, k): (usize, usize) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    if k % 2 == 0 {
        println!("-1");
        return;
    }

    let mut v: Vec<_> = (0..n).collect();

    let mut reached = false;

    foo(&mut v[..], 1, k, &mut reached);

    if reached {
        for i in v {
            print!("{} ", i + 1);
        }
        println!("");
    } else {
        println!("-1");
    }
}

fn foo(a: &mut[usize], mut count: usize, target: usize, reached: &mut bool) {
    let mid = a.len() / 2;
    let len = a.len();
    if count < target {
        a.swap(mid - 1, mid);
        count += 2;
    }
    if count < target && mid > 1 {
        foo(&mut a[..mid], count, target, reached);
    }
    if count < target && len > 2{
        foo(&mut a[mid..], count, target, reached);
    }
    if count == target {
        *reached = true;
    }
}


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k-1]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or l==mid:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid)
  solve(mid,r)

solve(0,n)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  mid = (l+r)/2
  if (arr[l:r+1])==sorted(arr[l:r+1]) or l==mid:
    return
  check(l,mid)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n)

if ans[0]==k:
  print temp
else:
  print -1


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or mid==l:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid-1)
  solve(mid,r)

ans[0] -= 1
solve(0,n)
print " ".join([str(x) for x in arr])
'''
ans[0] = 1
def check(l,r):
  if (arr[l:r+1])==sorted(arr[l:r+1]):
    return
  mid = (l+r)/2
  check(l,mid-1)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n)
print ans[0]'''


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or mid==l:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid-1)
  solve(mid,r)

ans[0] -= 1
solve(0,n)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  if (arr[l:r+1])==sorted(arr[l:r+1]):
    return
  mid = (l+r)/2
  check(l,mid-1)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n)

if ans[0]==k:
  print temp
else:
  print -1


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or l==mid:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid)
  solve(mid,r)

ans[0] -= 1
solve(0,n-1)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  mid = (l+r)/2
  if (arr[l:r+1])==sorted(arr[l:r+1]) or l==mid:
    return
  check(l,mid)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n-1)

if ans[0]==k:
  print temp
else:
  print -1


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0:
    return
  ans[0] -= 2
  arr[mid],arr[mid+1] = arr[mid+1],arr[mid]
  solve(l,mid)
  solve(mid+1,r)

ans[0] -= 1
solve(0,n)
print " ".join([str(x) for x in arr])


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k-1]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or l==mid:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid)
  solve(mid,r)

solve(0,n)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  mid = (l+r)/2
  if (arr[l:r+1])==sorted(arr[l:r+1]) or l==mid:
    return
  check(l,mid)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n)
print temp
'''if ans[0]==k:
  print temp
else:
  print -1'''


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k-1]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or l==mid:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid)
  solve(mid,r)

solve(0,n-1)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  mid = (l+r)/2
  if (arr[l:r+1])==sorted(arr[l:r+1]) or l==mid:
    return
  check(l,mid)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n-1)
print temp


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or mid==l:
    return
  ans[0] -= 2
  arr[mid-1],arr[mid] = arr[mid],arr[mid-1]
  solve(l,mid)
  solve(mid+1,r)

ans[0] -= 1
solve(0,n-1)
print " ".join([str(x) for x in arr])


import sys
n,k = map(int,raw_input().split())
if (k%2==0):
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or mid==l:
    return
  ans[0] -= 2
  arr[mid-1],arr[mid] = arr[mid],arr[mid-1]
  solve(l,mid)
  solve(mid+1,r)

ans[0] -= 1
solve(0,n)
print " ".join([str(x) for x in arr])


import sys
n,k = map(int,raw_input().split())
if (k%2==0) or k > n*2:
  print -1
  sys.exit()

arr = [x for x in range(1,n+1)]
ans = [k-1]

def solve(l,r):
  mid = (l+r)/2
  if ans[0]==0 or l==mid:
    return
  ans[0] -= 2
  arr[mid],arr[mid-1] = arr[mid-1],arr[mid]
  solve(l,mid)
  solve(mid,r)

solve(0,n)
temp = " ".join([str(x) for x in arr])
ans[0] = 1
def check(l,r):
  mid = (l+r)/2
  if (arr[l:r+1])==sorted(arr[l:r+1]) or l==mid:
    return
  check(l,mid)
  check(mid,r)
  ans[0] += 2
  arr[l:r+1] = sorted(arr[l:r+1])

check(0,n)
print temp


from __future__ import division
from sys import stdin, stdout
from collections import deque, defaultdict, Counter

# from fractions import gcd
# from math import *
# from operator import mul
# from functools import reduce
# from copy import copy

rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in stdin.readline().split()]
rint = lambda: int(stdin.readline())
rints = lambda: [int(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
out = []

n, k = rints()
if k >= n << 1 or not (k & 1):
    print(-1)
    exit()

stk, ans, cur = [list(range(1, n + 1))], deque([]), 1

while stk and cur != k:
    ele = stk.pop()

    if len(ele) == 1:
        ans.extendleft(ele)
        continue

    md = len(ele) >> 1
    ele[md], ele[md - 1] = ele[md - 1], ele[md]
    cur += 2
    stk.extend([ele[:md], ele[md:]])

while stk:
    ans.extendleft(stk.pop()[::-1])

pr(ans, ' ')


import java.io.*;
import java.util.*;

public class Main
{

    public static final long q = 1000000000 + 7;

    public static void main(String[] args)
    {
        Scanner cin = new Scanner (System.in);
        String S = cin.nextLine();
        int N = S.length();
        long [] H = new long [N + 1];
        long [] p = new long [N + 1];
        H[0] = 0;
        for (int i = 0; i < N; i++)
            H[i + 1] = (H[i]*1998 + S.charAt(i)) % q;
        p[0] = 1;
        for (int i = 1; i <= N; i++) p[i] = (p[i - 1]*1998) % q;
        int start = -1, len = -1;
        for (int i = 2; i < N; i++)
        {
            int d = 1, c = N - i + 2, g;
            while (d + 1 < c)
            {
                g = (d + c) >> 1;
                long A = H[g];
                long B = (H[N] - H[N - g]*p[g] + q*q) % q;
                long C = (H[i + g - 1] - H[i - 1]*p[g]+ q*q) % q;
                if (A == B && B == C)
                {
                    if (g > len) {len = g; start = i;}
                    d = g;
                }
                else c = g;
            }
        }

        if (start == -1) System.out.print("Just a legend");
        else System.out.print(S.substring(start - 1, start + len - 1));
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{

    public static final long q = 1000000000 + 7;
    public static String S;
    public static int N;
    public static int [] A;
    public static int [] B;

    public static char Get(int k, int i)
    {
        if (k == 0) return S.charAt(i);
        else return S.charAt(N - i - 1);
    }

    public static int [] CalC(int status)
    {
        int [] Z = new int [N];
        Z[0] = N;
        int L = 0, R = 0;
        for (int i = 1; i < N; i++)
            if (i > R)
            {
                L = R = i;
                while (R < N && Get(status, R - L) == Get(status, R)) R++;
                Z[i] = R - L;
                R--;
            }
            else
            {
                int k = i - L;
                if (Z[k] < R - i + 1) Z[i] = Z[k];
                else
                {
                    L = i;
                    while (R < N && Get(status, R - L) == Get(status, R)) R++;
                    Z[i] = R - L;
                    R--;
                }
            }
        return Z;
    }

    public static void main(String[] args)
    {
        Scanner cin = new Scanner (System.in);
        S = cin.nextLine();
        N = S.length();

        int [] A = new int [N];
        A = CalC(0);
        int [] B = new int [N];
        B = CalC(1);
        for (int L = 0, R = N - 1, tmp; L < R; L++, R--)
        {
            tmp = B[L];
            B[L] = B[R];
            B[R] = tmp;
        }
        int [] C = new int [N];
        for (int i = N - 1; i >= 0; i--)
        {
            if (B[i] == 0) continue;
            int k = i - B[i] + 1;
            if (B[i] != N) C[k] = Math.max(C[k], B[i]);
        }

        int len = -1, start = -1;
        int ans = C[0] - 1;

        for (int i = 1; i < N - 1; i++, ans--)
        {
            ans = Math.max(ans, C[i]);
            int tmp = Math.min(ans, A[i]);
            if (tmp > 0 && tmp > len)
            {
                len = tmp;
                start = i;
            }
        }

        if (len > 0) System.out.print(S.substring(start, start + len));
        else System.out.print("Just a legend");
    }

}


import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
    static long mod=((long)1e9)+7;//toString
    public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
    public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;}
    public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;}
    public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;}

    public static void main (String[] args) throws java.lang.Exception
    {
        Reader sn = new Reader();
        Print p = new Print();
        StringBuilder a = new StringBuilder(sn.readWord());
        int n = a.length();
        int[] z = new int[ n ];
        for( int i = 1, l = 0, r = 0; i < n; ++i ){
            if( i <= r ){
                z[i] = Math.min( z[i - l], r - i + 1 );
            }
            while( i + z[i] < n && a.charAt(z[i]) == a.charAt( z[i] + i ) ){
                ++z[i];
            }
            if( z[i] + i - 1 > r ){
                l = i;r = i + z[i] - 1;
            }
        }
        int mid = -1;
        for( int i = 1; i < n-1; ++i ){
            if( i + z[i] == n )
            mid = Math.max( mid, z[i] - 1 );
            else
            mid = Math.max( mid, z[i] );
        }
        int len = 0;int in = -1;
        for( int i = 1; i < n; ++i ){
            if( z[i] <= mid  && i + z[i] == n ){
                if( z[i] > len ){
                    in = i;
                    len = z[i];
                }
            }
        }
        if( in != -1){
            p.printLine( a.substring( in, in + len ) );
        }
        else{
            p.printLine("Just a legend");
        }
        p.close();
    }
}
class Pair implements Comparable<Pair> {
		int val;
		int in;
		Pair(int a, int b){
			val=a;
	        in=b;
		}
		@Override
		public int compareTo(Pair o) {
			if(val==o.val)
			return Integer.compare(in,o.in);
			else
			return Integer.compare(val,o.val);
		}}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readWord()throws IOException
        {
		int c = read();
		while (isSpaceChar(c)) c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		}while (!isSpaceChar(c));
		return res.toString();
	    }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
class Print
{
    private final BufferedWriter bw;
    public Print()
    {
        bw=new BufferedWriter(new OutputStreamWriter(System.out));
    }
    public void print(String str)throws IOException
    {
        bw.append(str);
    }
    public void printLine(String str)throws IOException
    {
        print(str);
        bw.append("\n");
    }
    public void close()throws IOException
    {
        bw.close();
    }}


import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
    static long mod=((long)1e9)+7;//toString
    public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
    public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;}
    public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;}
    public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;}

    public static void main (String[] args) throws java.lang.Exception
    {
        Reader sn = new Reader();
        Print p = new Print();
        String a = sn.readWord();
        int n = a.length();
        int[] z = new int[ n ];
        for( int i = 0, l = 0, r = 0; i < n; ++i ){
            if( i <= r ){
                z[i] = Math.min( z[i - l], r - i + 1 );
            }
            while( i + z[i] < n && a.charAt(z[i]) == a.charAt( z[i] + i ) ){
                ++z[i];
            }
            if( z[i] + i - 1 > r ){
                l = i;r = i + z[i] - 1;
            }
        }
        int mid = -1;
        for( int i = 1; i < n-1; ++i ){
            if( i + z[i] == n )
            mid = Math.max( mid, z[i] - 1 );
            else
            mid = Math.max( mid, z[i] );
        }
        int len = 0;int in = -1;
        for( int i = 1; i < n; ++i ){
            if( z[i] <= mid ){
                if( z[i] > len ){
                    in = i;
                    len = z[i];
                }
            }
        }
        if( in != -1){
            p.printLine( a.substring( in, in + len ) );
        }
        else{
            p.printLine("Just a legend");
        }
        p.close();
    }
}
class Pair implements Comparable<Pair> {
		int val;
		int in;
		Pair(int a, int b){
			val=a;
	        in=b;
		}
		@Override
		public int compareTo(Pair o) {
			if(val==o.val)
			return Integer.compare(in,o.in);
			else
			return Integer.compare(val,o.val);
		}}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readWord()throws IOException
        {
		int c = read();
		while (isSpaceChar(c)) c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		}while (!isSpaceChar(c));
		return res.toString();
	    }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
class Print
{
    private final BufferedWriter bw;
    public Print()
    {
        bw=new BufferedWriter(new OutputStreamWriter(System.out));
    }
    public void print(String str)throws IOException
    {
        bw.append(str);
    }
    public void printLine(String str)throws IOException
    {
        print(str);
        bw.append("\n");
    }
    public void close()throws IOException
    {
        bw.close();
    }}


import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
    static long mod=((long)1e9)+7;//toString
    public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
    public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;}
    public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;}
    public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;}

    public static void main (String[] args) throws java.lang.Exception
    {
        Reader sn = new Reader();
        Print p = new Print();
        StringBuilder a = new StringBuilder(sn.readWord());
        int n = a.length();
        int[] z = new int[ n ];
        for( int i = 0, l = 0, r = 0; i < n; ++i ){
            if( i <= r ){
                z[i] = Math.min( z[i - l], r - i + 1 );
            }
            while( i + z[i] < n && a.charAt(z[i]) == a.charAt( z[i] + i ) ){
                ++z[i];
            }
            if( z[i] + i - 1 > r ){
                l = i;r = i + z[i] - 1;
            }
        }
        int mid = -1;
        for( int i = 1; i < n-1; ++i ){
            if( i + z[i] == n )
            mid = Math.max( mid, z[i] - 1 );
            else
            mid = Math.max( mid, z[i] );
        }
        int len = 0;int in = -1;
        for( int i = 1; i < n; ++i ){
            if( z[i] <= mid  && i + z[i] == n ){
                if( z[i] > len ){
                    in = i;
                    len = z[i];
                }
            }
        }
        if( in != -1){
            p.printLine( a.substring( in, in + len ) );
        }
        else{
            p.printLine("Just a legend");
        }
        p.close();
    }
}
class Pair implements Comparable<Pair> {
		int val;
		int in;
		Pair(int a, int b){
			val=a;
	        in=b;
		}
		@Override
		public int compareTo(Pair o) {
			if(val==o.val)
			return Integer.compare(in,o.in);
			else
			return Integer.compare(val,o.val);
		}}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readWord()throws IOException
        {
		int c = read();
		while (isSpaceChar(c)) c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		}while (!isSpaceChar(c));
		return res.toString();
	    }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
class Print
{
    private final BufferedWriter bw;
    public Print()
    {
        bw=new BufferedWriter(new OutputStreamWriter(System.out));
    }
    public void print(String str)throws IOException
    {
        bw.append(str);
    }
    public void printLine(String str)throws IOException
    {
        print(str);
        bw.append("\n");
    }
    public void close()throws IOException
    {
        bw.close();
    }}


import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
    static long mod=((long)1e9)+7;//toString
    public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
    public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;}
    public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;}
    public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;}

    public static void main (String[] args) throws java.lang.Exception
    {
        Reader sn = new Reader();
        Print p = new Print();
        String a = sn.readWord();
        int n = a.length();
        int[] z = new int[ n ];
        for( int i = 0, l = 0, r = 0; i < n; ++i ){
            if( i <= r ){
                z[i] = Math.min( z[i - l], r - i + 1 );
            }
            while( i + z[i] < n && a.charAt(z[i]) == a.charAt( z[i] + i ) ){
                ++z[i];
            }
            if( z[i] + i - 1 > r ){
                l = i;r = i + z[i] - 1;
            }
        }
        int mid = -1;
        for( int i = 1; i < n-1; ++i ){
            if( i + z[i] == n )
            mid = Math.max( mid, z[i] - 1 );
            else
            mid = Math.max( mid, z[i] );
        }
        int len = 0;int in = -1;
        for( int i = 1; i < n; ++i ){
            if( z[i] <= mid  && i + z[i] == n ){
                if( z[i] > len ){
                    in = i;
                    len = z[i];
                }
            }
        }
        if( in != -1){
            p.printLine( a.substring( in, in + len ) );
        }
        else{
            p.printLine("Just a legend");
        }
        p.close();
    }
}
class Pair implements Comparable<Pair> {
		int val;
		int in;
		Pair(int a, int b){
			val=a;
	        in=b;
		}
		@Override
		public int compareTo(Pair o) {
			if(val==o.val)
			return Integer.compare(in,o.in);
			else
			return Integer.compare(val,o.val);
		}}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readWord()throws IOException
        {
		int c = read();
		while (isSpaceChar(c)) c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		}while (!isSpaceChar(c));
		return res.toString();
	    }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
class Print
{
    private final BufferedWriter bw;
    public Print()
    {
        bw=new BufferedWriter(new OutputStreamWriter(System.out));
    }
    public void print(String str)throws IOException
    {
        bw.append(str);
    }
    public void printLine(String str)throws IOException
    {
        print(str);
        bw.append("\n");
    }
    public void close()throws IOException
    {
        bw.close();
    }}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);
	public static final String jl = "Just a legend";

	public static void main(String[] args) {
		final String s = in.next();

		int[] b = genKPMprecomputed(s);

		int last = b[b.length-1];

		boolean pos = false;

		while (last > 0 && !pos){
			for(int i = last; i < b.length - 1; i++) {
				if(b[i] == last) {
					pos = true;
					break;
				}
			}
			if(!pos) last = b[last];
		}

		if(last <= 0){
			System.out.println(jl);
		}else {
			System.out.println(s.substring(0,last));
		}
	}

	private static int[] genKPMprecomputed(final String s){
		int b[] = new int[s.length()+1];
		int i = 0, j = -1;
		b[0] = -1;
		while(i < s.length()) {
			while(j >= 0 && s.charAt(i) != s.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}
		return b;
	}
}


//package com.eduardocastillop.quartilmob;

import java.util.Set;
import java.util.TreeSet;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		Set<String> ps = new TreeSet<String>();

		final String s = in.next();

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < len; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		if(fi < 3){
			System.out.println("Just a legend");
			return;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);
		//System.out.println(mid);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}
}


import java.util.Set;
import java.util.TreeSet;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		Set<String> ps = new TreeSet<String>();

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
				return;
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < len; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		if(fi < 3){
			System.out.println("Just a legend");
			return;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);
		//System.out.println(mid);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}
}


//package com.eduardocastillop.quartilmob;

import java.util.Set;
import java.util.TreeSet;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		Set<String> ps = new TreeSet<String>();

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < len; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		if(fi < 3){
			System.out.println("Just a legend");
			return;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);
		//System.out.println(mid);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}
}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
				return;
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		final int max_len = KPM_LPS(s);
		//System.out.println(max_len);

		if(max_len == 0){
			System.out.println("Just a legend");
			return;
		}

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < max_len+1; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}

	static int KPM_LPS(final String str){
		int m = str.length(),b[] = new int[m+5];
		int i = 0, j = -1; b[0] = -1;
		while (i < m){
			while (j >= 0 && str.charAt(i) != str.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}

		return b[m];
	}
}


package com.eduardocastillop.quartilmob;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);
	public static final String jl = "Just a legend";

	public static void main(String[] args) {
		final String s = in.next();
		if(s.length() < 3){
			System.out.println(jl);
			return;
		}

		if(s.length() == 3){
			final char[] cs = s.toCharArray();
			if(cs[0] == cs[1] && cs[1] == cs[2]) {
				System.out.println(cs[0]);
			}
			else {
				System.out.println(jl);
			}
			return;
		}

		int[] failure = genKPMprecomputed(s);

		int xmax = failure[failure.length-1];

		boolean imposs = true;

		while (xmax > 0 && !imposs){
			for(int i = xmax; i < failure.length - 1; i++) {
				if(failure[i] == xmax) {
					imposs = false;
					break;
				}
			}
			if(imposs) xmax = failure[xmax];
		}

		if(xmax <= 0){
			System.out.println(jl);
		}else {
			System.out.println(s.substring(0,xmax));
		}
	}

	private static int[] genKPMprecomputed(final String s){
		int b[] = new int[s.length()+1];
		int i = 0, j = -1;
		b[0] = -1;
		while(i < s.length()) {
			while(j >= 0 && s.charAt(i) != s.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}
		return b;
	}
}


import java.util.Set;
import java.util.TreeSet;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		Set<String> ps = new TreeSet<String>();

		final String s = in.next();

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < len; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);
		//System.out.println(mid);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}
}


package com.eduardocastillop.quartilmob;

import java.util.Set;
import java.util.TreeSet;

public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		Set<String> ps = new TreeSet<String>();

		final String s = in.next();

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < len; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);
		//System.out.println(mid);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}
}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		final int max_len = KPM_LPS(s);
		//System.out.println(max_len);

		if(max_len == 0){
			System.out.println("Just a legend");
			return;
		}

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < max_len+1; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}

	static int KPM_LPS(final String str){
		int m = str.length(),b[] = new int[m+5];
		int i = 0, j = -1; b[0] = -1;
		while (i < m){
			while (j >= 0 && str.charAt(i) != str.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}

		return b[m];
	}
}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		final int max_len = KPM_LPS(s);
		//System.out.println(max_len);

		if(max_len == 0){
			System.out.println("Just a legend"+max_len);
			return;
		}

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < max_len+1; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre) && mid.contains(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}

	static int KPM_LPS(final String str){
		int m = str.length(),b[] = new int[m+5];
		int i = 0, j = -1; b[0] = -1;
		while (i < m){
			while (j >= 0 && str.charAt(i) != str.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}

		return b[m];
	}
}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);
	public static final String jl = "Just a legend";

	public static void main(String[] args) {
		final String s = in.next();
		if(s.length() < 3){
			System.out.println(jl);
			return;
		}

		if(s.length() == 3){
			final char[] cs = s.toCharArray();
			if(cs[0] == cs[1] && cs[1] == cs[2]) {
				System.out.println(cs[0]);
			}
			else {
				System.out.println(jl);
			}
			return;
		}

		int[] failure = genKPMprecomputed(s);

		int xmax = failure[failure.length-1];

		boolean imposs = true;

		while (xmax > 0 && !imposs){
			for(int i = xmax; i < failure.length - 1; i++) {
				if(failure[i] == xmax) {
					imposs = false;
					break;
				}
			}
			if(imposs) xmax = failure[xmax];
		}

		if(xmax <= 0){
			System.out.println(jl);
		}else {
			System.out.println(s.substring(0,xmax));
		}
	}

	private static int[] genKPMprecomputed(final String s){
		int b[] = new int[s.length()+1];
		int i = 0, j = -1;
		b[0] = -1;
		while(i < s.length()) {
			while(j >= 0 && s.charAt(i) != s.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}
		return b;
	}
}


public class Main {
	private static final java.util.Scanner in = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		final String s = in.next();

		if(s.length() == 3){
			if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)){
				System.out.println(s.charAt(0));
				return;
			}
		}

		final char f = s.charAt(0);
		final char x = s.charAt(s.length()-1);
		final int len = s.length();

		final int max_len = KPM_LPS(s);
		//System.out.println(max_len);

		if(max_len == 0){
			System.out.println("Just a legend");
			return;
		}

		int[] fpos = new int[s.length()], xpos = new int[s.length()];

		int fi = 0,xi = 0;
		char c;

		for(int i = 0; i < max_len+1; i++){
			c = s.charAt(i);
			if(c == f) fpos[fi++] = i;
			else if(c == x) xpos[xi++] = i;
		}

		String pre, suf;
		final String mid = s.substring(1,len-1);

		for (int xin = xpos.length - 2; xin >= 1; xin--) {
			pre = s.substring(0,xin+1);
			if(s.endsWith(pre)) {
				System.out.println(pre);
				return;
			}
		}

		System.out.println("Just a legend");
	}

	static int KPM_LPS(final String str){
		int m = str.length(),b[] = new int[m+5];
		int i = 0, j = -1; b[0] = -1;
		while (i < m){
			while (j >= 0 && str.charAt(i) != str.charAt(j)) j = b[j];
			i++;
			j++;
			b[i] = j;
		}

		return b[m];
	}
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class SingleAllocationTrie {
	static int[][] t = new int[28][1 << 10];
	static int p = 1;

	static void add(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer] == 0 ? (t[c - 'a'][pointer] = p++) : t[c - 'a'][pointer];
		t[27][pointer] = 1;
	}

	static int get(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer];
		return pointer;
	}

	static boolean contains(String s) {
		return t[27][get(s)] == 1;
	}

	static int rk(String needle, String haystack) {
		if (haystack.length() < needle.length()) {
			return -1;
		}
		char[] h = haystack.toCharArray();
		long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
		for (char c : needle.toCharArray()) {
			pow *= BASE;
			needleHash += c;
			needleHash *= BASE;
		}
		for (char c : haystack.substring(0, needle.length()).toCharArray()) {
			haystackHash += c;
			haystackHash *= BASE;
		}
		if (haystackHash == needleHash && haystack.startsWith(needle)) {
			return 0;
		}
		for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
			haystackHash = haystackHash - pow * h[l] + h[r];
			haystackHash *= BASE;
			if (haystackHash == needleHash && haystack.substring(l + 1).startsWith(needle)) {
				return l + 1;
			}
		}
		return -1;

	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		int ans = -1;
		int l = 0, r = len.size();
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			int res = rk(s.substring(0, length), s.substring(1, s.length() - 1));
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int[][] dfa = new int[1_000_005][27];       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        for(int[] c : dfa){
            Arrays.fill(c, 0);
        }
        // build DFA from pattern
        int m = pat.length();
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < dfa[0].length; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int[][] dfa = new int[27][1_000_005];       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        for(int[] c : dfa){
            Arrays.fill(c, 0);
        }
        // build DFA from pattern
        int m = pat.length();
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < 26; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}