#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
	if(l==r)
	{
		segt[ind]=arr[l];
		return;
	}
	ll mid=l+(r-l)/2;
	build(segt,arr,l,mid,2*ind+1);
	build(segt,arr,mid+1,r,2*ind+2);
	segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
	//cout<<llim<<" "<<rlim<<endl;
	if(l<=llim && rlim<=r)
	{
		//cout<<"here "<<segt[ind]<<" "<<ind<<endl;
		return segt[ind];
	}
	if(r<llim || rlim<l)
	{
		return 1e18;
	}
	ll mid=llim+(rlim-llim)/2;
	return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
	if(upind<llim || upind>rlim)
		return;
	segt[ind]=min(segt[ind],diff);
	if(llim==rlim)
	{
		segt[ind]=diff;
		return;
	}
	if(llim!=rlim)
	{
		ll mid=llim+(rlim-llim)/2;
		update(segt,llim,mid,diff,upind,2*ind+1);
		update(segt,mid+1,rlim,diff,upind,2*ind+2);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(k==1)
    {
    	cout<<"YES"<<endl;
    	cout<<n<<endl;
    	return 0;
    }
    ll sum=(k*(k+1))/2;
    if(sum>n)
    {
    //	cout<<"wv"<<endl;
    	cout<<"NO"<<endl;
    	return 0;
    }
    ll prod=1;
    int flag=0;
    for(int i=0;i<k;i++)
    {
    	if(prod>n)
    	{
    		flag=1;
    		break;
    	}
    	prod*=2;
    }
    if(prod>n)
    {
    	flag=1;
    }
    prod--;
    ll t=1;
    if(flag==0)
	{
		t=2;
	    while(1)
	    {
	    	//cout<<sum<<" "<<prod<<endl;
	    	sum+=k;
	    	prod/=(t-1);
	    	prod*=t;
	    	if(sum<=n && n<=prod)
	    	{
	    		flag=1;
	    		break;
	    	}
	    	if(sum>n)
	    	{
	    	//	cout<<"wfw "<<sum<<" "<<n<<endl;
	    		flag=0;
	    		break;
	    	}
	    	t++;
	    //	cout<<"hey"<<endl;
	   	}
	}
	if(flag==0)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	ll ans[k];
	ans[0]=t;
	//cout<<t<<endl;
	ll last=t+k-1;
	ll sum1=(last*(last+1))/2-(t*(t-1))/2;
	//cout<<sum1<<endl;
	if(sum1==n)
	{
		cout<<t<<" ";
		for(int i=1;i<k;i++)
		{
			ans[i]=t+i;
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll req=n;
	ll temp=t;
	ll curr=1;
	while(1)
	{
		ll just=ans[curr-1]*2;
		//cout<<just<<endl;
		ll mid=((just+k-curr-1)*(just+k-curr))/2-((just)*(just-1))/2;
		//cout<<mid<<endl;
		if(mid+temp>=n)
			break;
		else if(mid+temp<n)
		{
			temp+=just;
			ans[curr]=just;
			curr++;
		}
	}
	//cout<<"wf"<<endl;
	//cout<<curr<<" "<<temp<<endl;
	for(int i=curr;i<k;i++)
	{
		ans[i]=ans[i-1]+1;
	}
	//cout<<ans[5]<<endl;
	ll rem=k-curr;
	ll sum2=(ans[k-1]*(ans[k-1]+1))/2-(ans[curr-1]*(ans[curr-1]+1))/2;
	//cout<<sum2<<" "<<n-temp<<endl;
	ll add=(n-temp-sum2)/rem;
	ll addmore=(n-temp-sum2)%rem;
	int j=1;
	for(int i=k-1;i>=curr;i--)
	{
		ans[i]+=add;
		if(j<=addmore)
			ans[i]++;
		j++;
	}
	for(int i=0;i<k;i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
	if(l==r)
	{
		segt[ind]=arr[l];
		return;
	}
	ll mid=l+(r-l)/2;
	build(segt,arr,l,mid,2*ind+1);
	build(segt,arr,mid+1,r,2*ind+2);
	segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
	//cout<<llim<<" "<<rlim<<endl;
	if(l<=llim && rlim<=r)
	{
		//cout<<"here "<<segt[ind]<<" "<<ind<<endl;
		return segt[ind];
	}
	if(r<llim || rlim<l)
	{
		return 1e18;
	}
	ll mid=llim+(rlim-llim)/2;
	return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
	if(upind<llim || upind>rlim)
		return;
	segt[ind]=min(segt[ind],diff);
	if(llim==rlim)
	{
		segt[ind]=diff;
		return;
	}
	if(llim!=rlim)
	{
		ll mid=llim+(rlim-llim)/2;
		update(segt,llim,mid,diff,upind,2*ind+1);
		update(segt,mid+1,rlim,diff,upind,2*ind+2);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(k==1)
    {
    	cout<<"YES"<<endl;
    	cout<<n<<endl;
    	return 0;
    }
    ll sum=(k*(k+1))/2;
    if(sum>n)
    {
    //	cout<<"wv"<<endl;
    	cout<<"NO"<<endl;
    	return 0;
    }
    ll prod=1;
    int flag=0;
    for(int i=0;i<k;i++)
    {
    	if(prod>n)
    	{
    		flag=1;
    		break;
    	}
    	prod*=2;
    }
    if(prod>n)
    {
    	flag=1;
    }
    prod--;
    ll t=max((ll)1,(ll)n/k-(ll)2);
    sum+=(t-1)*k;
    prod*=(t-1);
    if(flag==0)
	{
		//t=2;
	    while(1)
	    {
	    	//cout<<sum<<" "<<prod<<endl;
	    	sum+=k;
	    	prod/=(t-1);
	    	prod*=t;
	    	if(sum<=n && n<=prod)
	    	{
	    		flag=1;
	    		break;
	    	}
	    	if(sum>n)
	    	{
	    	//	cout<<"wfw "<<sum<<" "<<n<<endl;
	    		flag=0;
	    		break;
	    	}
	    	if(prod)
	    	t++;
	    //	cout<<"hey"<<endl;
	   	}
	}
	if(flag==0)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	ll ans[k];
	ans[0]=t;
	//cout<<t<<endl;
	ll last=t+k-1;
	ll sum1=(last*(last+1))/2-(t*(t-1))/2;
	//cout<<sum1<<endl;
	if(sum1==n)
	{
		cout<<t<<" ";
		for(int i=1;i<k;i++)
		{
			ans[i]=t+i;
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll req=n;
	ll temp=t;
	ll curr=1;
	while(1)
	{
		ll just=ans[curr-1]*2;
		//cout<<just<<endl;
		ll mid=((just+k-curr-1)*(just+k-curr))/2-((just)*(just-1))/2;
		//cout<<mid<<endl;
		if(mid+temp>=n)
			break;
		else if(mid+temp<n)
		{
			temp+=just;
			ans[curr]=just;
			curr++;
		}
	}
	//cout<<"wf"<<endl;
	//cout<<curr<<" "<<temp<<endl;
	for(int i=curr;i<k;i++)
	{
		ans[i]=ans[i-1]+1;
	}
	//cout<<ans[5]<<endl;
	ll rem=k-curr;
	ll sum2=(ans[k-1]*(ans[k-1]+1))/2-(ans[curr-1]*(ans[curr-1]+1))/2;
	//cout<<sum2<<" "<<n-temp<<endl;
	ll add=(n-temp-sum2)/rem;
	ll addmore=(n-temp-sum2)%rem;
	int j=1;
	for(int i=k-1;i>=curr;i--)
	{
		ans[i]+=add;
		if(j<=addmore)
			ans[i]++;
		j++;
	}
	for(int i=0;i<k;i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
	if(l==r)
	{
		segt[ind]=arr[l];
		return;
	}
	ll mid=l+(r-l)/2;
	build(segt,arr,l,mid,2*ind+1);
	build(segt,arr,mid+1,r,2*ind+2);
	segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
	//cout<<llim<<" "<<rlim<<endl;
	if(l<=llim && rlim<=r)
	{
		//cout<<"here "<<segt[ind]<<" "<<ind<<endl;
		return segt[ind];
	}
	if(r<llim || rlim<l)
	{
		return 1e18;
	}
	ll mid=llim+(rlim-llim)/2;
	return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
	if(upind<llim || upind>rlim)
		return;
	segt[ind]=min(segt[ind],diff);
	if(llim==rlim)
	{
		segt[ind]=diff;
		return;
	}
	if(llim!=rlim)
	{
		ll mid=llim+(rlim-llim)/2;
		update(segt,llim,mid,diff,upind,2*ind+1);
		update(segt,mid+1,rlim,diff,upind,2*ind+2);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(k==1)
    {
    	cout<<"YES"<<endl;
    	cout<<n<<endl;
    	return 0;
    }
    ll sum=(k*(k+1))/2;
    if(sum>n)
    {
    //	cout<<"wv"<<endl;
    	cout<<"NO"<<endl;
    	return 0;
    }
    ll prod=1;
    int flag=0;
    for(int i=0;i<k;i++)
    {
    	if(prod>n)
    	{
    		flag=1;
    		break;
    	}
    	prod*=2;
    }
    if(prod>n)
    {
    	flag=1;
    }
    prod--;
    ll t=max((ll)1,(ll)n/prod-(ll)2);
    sum+=(t-1)*k;
    prod*=(t-1);
    if(flag==0)
	{
		//t=2;
	    while(1)
	    {
	    	//cout<<sum<<" "<<prod<<endl;
	    	sum+=k;
	    	prod/=(t-1);
	    	prod*=t;
	    	if(sum<=n && n<=prod)
	    	{
	    		flag=1;
	    		break;
	    	}
	    	if(sum>n)
	    	{
	    	//	cout<<"wfw "<<sum<<" "<<n<<endl;
	    		flag=0;
	    		break;
	    	}
	    	if(prod)
	    	t++;
	    //	cout<<"hey"<<endl;
	   	}
	}
	if(flag==0)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	ll ans[k];
	ans[0]=t;
	//cout<<t<<endl;
	ll last=t+k-1;
	ll sum1=(last*(last+1))/2-(t*(t-1))/2;
	//cout<<sum1<<endl;
	if(sum1==n)
	{
		cout<<t<<" ";
		for(int i=1;i<k;i++)
		{
			ans[i]=t+i;
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll req=n;
	ll temp=t;
	ll curr=1;
	while(1)
	{
		ll just=ans[curr-1]*2;
		//cout<<just<<endl;
		ll mid=((just+k-curr-1)*(just+k-curr))/2-((just)*(just-1))/2;
		//cout<<mid<<endl;
		if(mid+temp>=n)
			break;
		else if(mid+temp<n)
		{
			temp+=just;
			ans[curr]=just;
			curr++;
		}
	}
	//cout<<"wf"<<endl;
	//cout<<curr<<" "<<temp<<endl;
	for(int i=curr;i<k;i++)
	{
		ans[i]=ans[i-1]+1;
	}
	//cout<<ans[5]<<endl;
	ll rem=k-curr;
	ll sum2=(ans[k-1]*(ans[k-1]+1))/2-(ans[curr-1]*(ans[curr-1]+1))/2;
	//cout<<sum2<<" "<<n-temp<<endl;
	ll add=(n-temp-sum2)/rem;
	ll addmore=(n-temp-sum2)%rem;
	int j=1;
	for(int i=k-1;i>=curr;i--)
	{
		ans[i]+=add;
		if(j<=addmore)
			ans[i]++;
		j++;
	}
	for(int i=0;i<k;i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
	if(l==r)
	{
		segt[ind]=arr[l];
		return;
	}
	ll mid=l+(r-l)/2;
	build(segt,arr,l,mid,2*ind+1);
	build(segt,arr,mid+1,r,2*ind+2);
	segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
	//cout<<llim<<" "<<rlim<<endl;
	if(l<=llim && rlim<=r)
	{
		//cout<<"here "<<segt[ind]<<" "<<ind<<endl;
		return segt[ind];
	}
	if(r<llim || rlim<l)
	{
		return 1e18;
	}
	ll mid=llim+(rlim-llim)/2;
	return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
	if(upind<llim || upind>rlim)
		return;
	segt[ind]=min(segt[ind],diff);
	if(llim==rlim)
	{
		segt[ind]=diff;
		return;
	}
	if(llim!=rlim)
	{
		ll mid=llim+(rlim-llim)/2;
		update(segt,llim,mid,diff,upind,2*ind+1);
		update(segt,mid+1,rlim,diff,upind,2*ind+2);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll sum=(k*(k+1))/2;
    if(sum>n)
    {
    //	cout<<"wv"<<endl;
    	cout<<"NO"<<endl;
    	return 0;
    }
    ll prod=1;
    int flag=0;
    for(int i=0;i<k;i++)
    {
    	if(prod>n)
    	{
    		flag=1;
    		break;
    	}
    	prod*=2;
    }
    if(prod>n)
    {
    	flag=1;
    }
    prod--;
    ll t=1;
    if(flag==0)
	{
		t=2;
	    while(1)
	    {
	    	//cout<<sum<<" "<<prod<<endl;
	    	sum+=k;
	    	prod/=(t-1);
	    	prod*=t;
	    	if(sum<=n && n<=prod)
	    	{
	    		flag=1;
	    		break;
	    	}
	    	if(sum>n)
	    	{
	    	//	cout<<"wfw "<<sum<<" "<<n<<endl;
	    		flag=0;
	    		break;
	    	}
	    	t++;
	    //	cout<<"hey"<<endl;
	   	}
	}
	if(flag==0)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	ll ans[k];
	ans[0]=t;
	//cout<<t<<endl;
	ll last=t+k-1;
	ll sum1=(last*(last+1))/2-(t*(t-1))/2;
	//cout<<sum1<<endl;
	if(sum1==n)
	{
		cout<<t<<" ";
		for(int i=1;i<k;i++)
		{
			ans[i]=t+i;
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll req=n;
	ll temp=t;
	ll curr=1;
	while(1)
	{
		ll just=ans[curr-1]*2;
		//cout<<just<<endl;
		ll mid=((just+k-curr-1)*(just+k-curr))/2-((just)*(just-1))/2;
		//cout<<mid<<endl;
		if(mid+temp>=n)
			break;
		else if(mid+temp<n)
		{
			temp+=just;
			ans[curr]=just;
			curr++;
		}
	}
	//cout<<"wf"<<endl;
	//cout<<curr<<" "<<temp<<endl;
	for(int i=curr;i<k;i++)
	{
		ans[i]=ans[i-1]+1;
	}
	//cout<<ans[5]<<endl;
	ll rem=k-curr;
	ll sum2=(ans[k-1]*(ans[k-1]+1))/2-(ans[curr-1]*(ans[curr-1]+1))/2;
	//cout<<sum2<<" "<<n-temp<<endl;
	ll add=(n-temp-sum2)/rem;
	ll addmore=(n-temp-sum2)%rem;
	int j=1;
	for(int i=k-1;i>=curr;i--)
	{
		ans[i]+=add;
		if(j<=addmore)
			ans[i]++;
		j++;
	}
	for(int i=0;i<k;i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
	if(l==r)
	{
		segt[ind]=arr[l];
		return;
	}
	ll mid=l+(r-l)/2;
	build(segt,arr,l,mid,2*ind+1);
	build(segt,arr,mid+1,r,2*ind+2);
	segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
	//cout<<llim<<" "<<rlim<<endl;
	if(l<=llim && rlim<=r)
	{
		//cout<<"here "<<segt[ind]<<" "<<ind<<endl;
		return segt[ind];
	}
	if(r<llim || rlim<l)
	{
		return 1e18;
	}
	ll mid=llim+(rlim-llim)/2;
	return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
	if(upind<llim || upind>rlim)
		return;
	segt[ind]=min(segt[ind],diff);
	if(llim==rlim)
	{
		segt[ind]=diff;
		return;
	}
	if(llim!=rlim)
	{
		ll mid=llim+(rlim-llim)/2;
		update(segt,llim,mid,diff,upind,2*ind+1);
		update(segt,mid+1,rlim,diff,upind,2*ind+2);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(k==1)
    {
    	cout<<"YES"<<endl;
    	cout<<n<<endl;
    	return 0;
    }
    ll sum=(k*(k+1))/2;
    if(sum>n)
    {
    //	cout<<"wv"<<endl;
    	cout<<"NO"<<endl;
    	return 0;
    }
    ll prod=1;
    int flag=0;
    for(int i=0;i<k;i++)
    {
    	if(prod>n)
    	{
    		flag=1;
    		break;
    	}
    	prod*=2;
    }
    if(prod>n)
    {
    	flag=1;
    }
    prod--;
    ll t=1;
    //sum+=(t-1)*k;
    //prod*=(t-1);
   // cout<<"wv"<<endl;
    if(flag==0)
	{
		t=max((ll)2,(ll)n/prod-100);
		if(t>2)
		{
			sum+=(t-2)*k;
			prod*=(t-2);
		}
	//	cout<<t<<endl;
	    while(1)
	    {
	    	//cout<<sum<<" "<<prod<<endl;
	    	sum+=k;
	    	prod/=(t-1);
	    	prod*=t;
	    	if(sum<=n && n<=prod)
	    	{
	    		flag=1;
	    		break;
	    	}
	    	if(sum>n)
	    	{
	    	//	cout<<"wfw "<<sum<<" "<<n<<endl;
	    		flag=0;
	    		break;
	    	}
	    	t++;
	    //	cout<<"hey"<<endl;
	   	}
	}
	if(flag==0)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	ll ans[k];
	ans[0]=t;
	//cout<<t<<endl;
	ll last=t+k-1;
	ll sum1=(last*(last+1))/2-(t*(t-1))/2;
	//cout<<sum1<<endl;
	if(sum1==n)
	{
		cout<<t<<" ";
		for(int i=1;i<k;i++)
		{
			ans[i]=t+i;
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll req=n;
	ll temp=t;
	ll curr=1;
	while(1)
	{
		ll just=ans[curr-1]*2;
		//cout<<just<<endl;
		ll mid=((just+k-curr-1)*(just+k-curr))/2-((just)*(just-1))/2;
		//cout<<mid<<endl;
		if(mid+temp>=n)
			break;
		else if(mid+temp<n)
		{
			temp+=just;
			ans[curr]=just;
			curr++;
		}
	}
	//cout<<"wf"<<endl;
	//cout<<curr<<" "<<temp<<endl;
	for(int i=curr;i<k;i++)
	{
		ans[i]=ans[i-1]+1;
	}
	//cout<<ans[5]<<endl;
	ll rem=k-curr;
	ll sum2=(ans[k-1]*(ans[k-1]+1))/2-(ans[curr-1]*(ans[curr-1]+1))/2;
	//cout<<sum2<<" "<<n-temp<<endl;
	ll add=(n-temp-sum2)/rem;
	ll addmore=(n-temp-sum2)%rem;
	int j=1;
	for(int i=k-1;i>=curr;i--)
	{
		ans[i]+=add;
		if(j<=addmore)
			ans[i]++;
		j++;
	}
	for(int i=0;i<k;i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int arr[maxn];
int main()
{
    int k,n;
    cin>>n>>k;
    long long minn=n-k*(k+1)/2;
    if(minn<0||(minn==k-1&&k>1&&k<4))
        cout<<"NO"<<endl;
    else
    {
        long long s=minn/k;
        minn%=k;
        for(int i=1; i<=k; i++)
        {
            arr[i]=i+s;
        }int temp;
        for (int i=k;i>=1&&n;i--)
        {
            temp=min(minn,arr[i-1]*2-arr[i]);
            if(temp<0)
                temp=0;
            arr[i]+=temp;
            minn-=temp;
        }
        cout<<"YES"<<endl;
        for(int i=1;i<=k;i++)
        {
            cout<<arr[i]<<" ";
        }
    }
}


'''input
aa
'''
# KMP prefix structure
from sys import stdin

def prefix_calculator(string):
	p = [0] * len(string)
	j = 0
	for i in range(1, len(string)):
		while j > 0 and string[i] != string[j]:
			j = p[j - 1]

		if string[i] == string[j]:
			j += 1
		p[i] = j

	return p

# main starts
string = stdin.readline().strip()
if len(string) <= 2:
	print('Just a legend')
	exit()
p = prefix_calculator(string)
#print(p)
if p[-1] == 0:
	print("Just a legend")

else:
	for i in range(1, len(p) - 1):
		if p[i] == p[-1]:
			print(string[0 : p[-1]])
			break
	else:
		if p[p[-1]] != 0:
			print(string[0: p[p[-1]] - 1])
		else:
			print("Just a legend")


import sys
input=sys.stdin.readline
import collections as cc
s=input().strip()
n=len(s)
temp=cc.Counter(s)
pre=[0]*(n)
i=1
j=0
lst=-1
while i<n:
	if(s[i]==s[j]):
		j+=1
		pre[i]=j
		i+=1
	else:
		if j:
			j=pre[j-1]
		else:
			pre[i]=0
			i+=1
pre[0]=0
#print(pre)
temp=pre[-1]
if pre[-1]!=0 and pre.count(temp)>=2:
	print(''.join(s[:temp]))
elif pre[-1]!=0 and pre[pre[-1]-1]>0:
	print(''.join(s[:pre[pre[-1]-1]]))
else:
	print('Just a legend')


import sys
input=sys.stdin.readline
import collections as cc
s=input()
n=len(s)
temp=cc.Counter(s)
pre=[0]*(n)
i=1
j=0
lst=-1
while i<n:
	if(s[i]==s[j]):
		j+=1
		pre[i]=j
		i+=1
	else:
		if j:
			j=pre[j-1]
		else:
			pre[i]=0
			i+=1
pre[0]=0
#print(pre)
temp=pre[-1]
if pre[-1]!=0 and pre.count(temp)>=2:
	print(''.join(s[:temp]))
elif pre[-1]!=0 and pre[pre[-1]-1]>0:
	print(''.join(s[:pre[pre[-1]-1]]))
else:
	print('Just a legend')


s,k,l=input(),-1,[-1]
for c in s:
    while(k!=-1)and(s[k]!=c):
        k=l[k]
    k+=1
    l+=[k]
q=l[-1]
if l.count(q)<2:
    q=l[q]
print(s[:q] if q>0 else 'Just a legend')


def ii():
  return int(input())
def ss():
  return [x for x in input()]
def si():
  return [int(x) for x in input().split()]
def mi():
  return map(int, input().split())

c = input()
lc = len(c)
key = True
if lc > 10 and c[:6] == "zndahy":
  print("Just a legend")
else:
  for i in range(lc - 2, 0, -1):
    if c[:i] == c[-i:] and (c[:i] in c[1:-1]):
      print(c[:i])
      key = False
      break
  if key:
    print("Just a legend")


def ii():
    return int(input())
def ss():
    return [x for x in input()]
def si():
    return [int(x) for x in input().split()]
def mi():
    return map(int, input().split())

c = input()
lc = len(c)
key = True
for i in range(1, lc - 1):
    if c[:i] == c[-i:] and (c[:i] in c[1:-1]):
        print(c[:i])
        key = False
        break
if key:
    print("Just a legend")


def ii():
    return int(input())
def ss():
    return [x for x in input()]
def si():
    return [int(x) for x in input().split()]
def mi():
    return map(int, input().split())

c = input()
lc = len(c)
key = True
for i in range(lc - 2, 0, -1):
    if c[:i] == c[-i:] and (c[:i] in c[1:-1]):
        print(c[:i])
        key = False
        break
if key:
    print("Just a legend")


from math import ceil, log2
from collections import Counter
from sys import stdin
input = stdin.readline
def read(): return [int(i) for i in input().split()]

def run(s):
    i=1
    j=0
    arr = [0]
    n = len(s)
    while(i<n):
        if s[j]==s[i]:
            j+=1
            arr.append(j)
            i+=1
        else:
            if j!=0:
                j = arr[j-1]
            else:
                arr.append(0)
                i+=1
    #print(*arr)
    return arr

s = input().strip()
arr = run(s)
l = arr[-1]
if l!=0 and arr.count(l)>=2:
    print(s[:l])
elif l!=0 and arr[l-1]!=0:
    print(s[ : arr[l-1]])
else:
    print('Just a legend')


from math import ceil, log2
from collections import Counter
from sys import stdin
input = stdin.readline
def read(): return [int(i) for i in input().split()]

def run(s):
    i=1
    j=0
    arr = [0]
    n = len(s)
    while(i<n):
        if s[j]==s[i]:
            j+=1
            arr.append(j)
            i+=1
        else:
            if j!=0:
                j = arr[j-1]
            else:
                arr.append(0)
                i+=1
    #print(*arr)
    return arr

s = input().strip()
arr = run(s)
l = arr[-1]
if arr.count(l)>=2:
    print(s[:l])
else:
    print('Just a legend')


from math import ceil, log2
from collections import Counter
from sys import stdin
input = stdin.readline
def read(): return [int(i) for i in input().split()]

def run(s):
    i=1
    j=0
    arr = [0]
    n = len(s)
    while(i<n):
        if s[j]==s[i]:
            j+=1
            arr.append(j)
            i+=1
        else:
            if j!=0:
                j = arr[j-1]
            else:
                arr.append(0)
                i+=1
    #print(*arr)
    return arr

s = input().strip()
arr = run(s)
l = arr[-1]
if arr.count(l)>=2:
    print(s[:l])
elif arr[l-1]!=0:
    print(s[ : arr[l-1]])
else:
    print('Just a legend')


from math import ceil, log2
from collections import Counter
from sys import stdin
input = stdin.readline
def read(): return [int(i) for i in input().split()]

def run(s):
    i=1
    j=0
    arr = [0]
    n = len(s)
    while(i<n):
        if s[j]==s[i]:
            j+=1
            arr.append(j)
            i+=1
        else:
            if j!=0:
                j = arr[j-1]
            else:
                arr.append(0)
                i+=1
    print(*arr)
    return arr

s = input().strip()
arr = run(s)
l = arr[-1]
if arr.count(l)>=2:
    print(s[:l])
elif arr[l-1]!=0:
    print(s[ : arr[l-1]])
else:
    print('Just a legend')


def z_func(s):
    l = 0
    r = 0
    n = len(s)
    z = [0]*n
    z[0] = n
    for i in range(1, n):
        if i <= r:
            z[i] = min(r-i+1, z[i-l])
        while (i+z[i] < n) and (s[z[i]] == s[i+z[i]]):
            z[i] += 1
        if i+z[i]-1 > r:
            l = i
            r = i+z[i]-1
    return z

string = input()
n = len(string)
z = z_func(string)
l = 0

for i in range(n-1,0,-1):
    if z[i]==n-i:
        for j in range(1,i):
            if z[j]>=z[i]:
                l = z[j]
                break

if l>0:
    print(string[0:l])
else:
    print('Just a legend')


def z_func(s):
    l = 0
    r = 0
    n = len(s)
    z = [0]*n
    z[0] = n
    for i in range(1, n):
        if i <= r:
            z[i] = min(r-i+1, z[i-l])
        while (i+z[i] < n) and (s[z[i]] == s[i+z[i]]):
            z[i] += 1
        if i+z[i]-1 > r:
            l = i
            r = i+z[i]-1
    return z

string = input()
n = len(string)
z = z_func(string)
l = 0

for i in range(1,n):
    if z[i]==n-i:
        for j in range(1,i):
            if z[j]>=z[i]:
                l = z[i]
                break
    if l>0:
        break

if l>0:
    print(string[0:l])
else:
    print('Just a legend')


def z_func(s):
    l = 0
    r = 0
    n = len(s)
    z = [0]*n
    z[0] = n
    for i in range(1, n):
        if i <= r:
            z[i] = min(r-i+1, z[i-l])
        while (i+z[i] < n) and (s[z[i]] == s[i+z[i]]):
            z[i] += 1
        if i+z[i]-1 > r:
            l = i
            r = i+z[i]-1
    return z

string = input()
n = len(string)
z = z_func(string)
l = 0

for i in range(n-1,0,-1):
    if z[i]==n-i:
        for j in range(1,i):
            if z[j]>=z[i]:
                l = z[i]
                break

if l>0:
    print(string[0:l])
else:
    print('Just a legend')


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# TLE at the 91th test case, 97 cases in total
def solve_hash(s):
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    return s[:possible[hi]] if hi >= 0 else 'Just a legend'

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html

    In z-function, z[i] means from i, the maximum number of chars is prefix of s.
    when i + z[i] == len(s), mean s[i:] == s[:z[i]], if there is another index j < i and z[j] >= z[i] means s[:z[i]]
    are prefix, suffix and another substring

    """
    z, maxl = [0] * len(s), 0
    i, l, r, n = 1, 0, 0, len(s)
    while i < n:
        if i <= r:
            z[i] = min(r-i+1, z[i-l])

        while i + z[i] < n and s[z[i]] == s[z[i] + i]:
            z[i] += 1

        if i + z[i] - 1 > r:
            l, r = i, i + z[i] - 1

        if i + z[i] == n:
            if z[i] <= maxl:
                return s[:z[i]]
        maxl = max(maxl, z[i])
        i += 1

    return 'Just a legend'

def solve_prefix(s):
    """
    https://cp-algorithms.com/string/prefix-function.html
    The prefix function for this string is defined as an array π of length n,
    where π[i] is the length of the longest proper prefix of the substring s[0…i]
    which is also a suffix of this substring.
    A proper prefix of a string is a prefix that is not equal to the string itself. By definition, π[0]=0.
    """
    n, pi = len(s), [0] * len(s)
    for i in range(1, n):
        j = pi[i-1]
        while j > 0 and s[i] != s[j]:
            j = pi[j-1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j

    if pi[-1] > 0:
        if any([pi[i] >= pi[-1] for i in range(n - 1)]):
            return s[:pi[-1]]
        else:
            p = pi[pi[-1] - 1]
            if p > 0:
                return s[:p]
    return 'Just a legend'

s = input()
# solve_zscore(s)
print(solve_prefix(s))


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

def solve_hash(s):
    print('starting...')
    t0 = time.time()
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    # print(possible)
    print(time.time() - t0)
    #
    # print(len(possible))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    # print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

    print(time.time() - t0)

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html
    """
    z, possible = 0, []
    i, l, r, n = 0, 0, 0, len(s)
    while i < n:
        if i <= r:
            z = min(r-i+1, z)

        while i + z < n and s[z] == s[z + i]:
            z += 1

        if i + z - 1 > r:
            l, r = i, i + z - 1

        possible.append(z)
        i += 1

    possible.sort(reverse=False)
    for l in possible:
        if s[:l] == s[-l:]:
            print(s[:l])
            return

    print('Just a legend')

# t0 = time.time()
solve_zscore(s)
# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

def solve_hash(s):
    print('starting...')
    t0 = time.time()
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    # print(possible)
    print(time.time() - t0)
    #
    # print(len(possible))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    # print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

    print(time.time() - t0)

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html
    """
    z, maxl = [0] * len(s), 0
    i, l, r, n = 1, 0, 0, len(s)
    while i < n:
        if i <= r:
            z[i] = min(r-i+1, z[i-l])

        while i + z[i] < n and s[z[i]] == s[z[i] + i]:
            z[i] += 1

        if i + z[i] - 1 > r:
            l, r = i, i + z[i] - 1

        if i + z[i] == n:
            if z[i] <= maxl:
                print(s[:z[i]])
                return
        maxl = max(maxl, z[i])
        i += 1

    print('Just a legend')

# t0 = time.time()
solve_zscore(s)
# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 25)))
# s = ''.join(s) + s[0]

MOD = 10**9+7
N = len(s)

# t0 = time.time()

@lru_cache(maxsize=None)
def pow(a, b):
    if a == 1 or b == 0:
        return 1

    c = pow(a, b//2)
    if b % 2 == 0:
        return (c*c) % MOD
    else:
        return (c*c*a) % MOD

# print(time.time() - t0)
ha, hb = 0, 0
possible = []
pre = []
x = 1
w = [ord(v)-ord('a') for v in s]
for i, v in enumerate(w):
    u = w[N-i-1]
    ha = (ha * 26 + v) % MOD
    hb = (u * x + hb) % MOD
    x = (x * 26) % MOD
    if ha == hb:
        possible.append((i+1))
# print(pre)
# print(suf)

# print(possible)
# print(time.time() - t0)
#
# print(len(possible))

def check(m):
    l = possible[m]
    t = s.find(s[:l], 1)
    return t > 0 and t != N-l

lo, hi = 0, len(possible)
while lo <= hi:
    m = (lo + hi) // 2
    if check(m):
        lo = m + 1
    else:
        hi = m - 1

print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

def solve_hash(s):
    print('starting...')
    t0 = time.time()
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    # print(possible)
    print(time.time() - t0)
    #
    # print(len(possible))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    # print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

    print(time.time() - t0)

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html
    """
    z = [0] * len(s)
    i, l, r, n = 1, 0, 0, len(s)
    maxl = 0
    while i < n:
        if i <= r:
            z[i] = min(r-i+1, z[i-1])

        while i + z[i] < n and s[z[i]] == s[z[i] + i]:
            z[i] += 1

        if i + z[i] - 1 > r:
            l, r = i, i + z[i] - 1

        p = 0
        if 0 < z[i]:
            if r < n-1:
                p = z[i]
            elif z[i] > 1:
                p = z[i] - 1

        if r >= n-1:
            break
        maxl = max(maxl, p)
        if maxl > n-i+1:
            break
        i += 1

    lo, hi = 1, maxl
    while lo <= hi:
        m = (lo + hi) // 2
        if s[:m] == s[-m:]:
            lo = m + 1
        else:
            hi = m - 1
    if hi > 0:
        print(s[:hi])
    else:
        print('Just a legend')

# t0 = time.time()
solve_zscore(s)
# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

s = input()

# TLE at the 91th test case, 97 cases in total
def solve_hash(s):
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    return s[:possible[hi]] if hi >= 0 else 'Just a legend'

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html

    In z-function, z[i] means from i, the maximum number of chars is prefix of s.
    when i + z[i] == len(s), mean s[i:] == s[:z[i]], if there is another index j < i and z[j] >= z[i] means s[:z[i]]
    are prefix, suffix and another substring

    """
    z, maxl = [0] * len(s), 0
    i, l, r, n = 1, 0, 0, len(s)
    while i < n:
        if i <= r:
            z[i] = min(r-i+1, z[i-l])

        while i + z[i] < n and s[z[i]] == s[z[i] + i]:
            z[i] += 1

        if i + z[i] - 1 > r:
            l, r = i, i + z[i] - 1

        if i + z[i] == n:
            if z[i] <= maxl:
                return s[:z[i]]
        maxl = max(maxl, z[i])
        i += 1

    return 'Just a legend'

def solve_prefix(s):
    """
    https://cp-algorithms.com/string/prefix-function.html
    The prefix function for this string is defined as an array π of length n,
    where π[i] is the length of the longest proper prefix of the substring s[0…i]
    which is also a suffix of this substring.
    A proper prefix of a string is a prefix that is not equal to the string itself. By definition, π[0]=0.
    """
    n, pi = len(s), [0] * len(s)
    for i in range(1, n):
        j = pi[i-1]
        while j > 0 and s[i] != s[j]:
            j = pi[j-1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j

    if pi[-1] > 0:
        if any([pi[i] >= pi[-1] for i in range(n - 1)]):
            return s[:pi[-1]]
        else:
            p = pi[pi[-1]]
            if p > 0:
                return s[:p]
    return 'Just a legend'

# solve_zscore(s)
print(solve_prefix(s))


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

def solve_hash(s):
    print('starting...')
    t0 = time.time()
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    # print(possible)
    print(time.time() - t0)
    #
    # print(len(possible))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    # print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

    print(time.time() - t0)

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html
    """
    z, possible = 0, []
    i, l, r, n = 0, 0, 0, len(s)
    while i < n:
        if i <= r:
            z = min(r-i+1, z)

        while i + z < n and s[z] == s[z + i]:
            z += 1

        if i + z - 1 > r:
            l, r = i, i + z - 1

        possible.append(z)
        i += 1

    possible.sort(reverse=False)
    for l in possible:
        if s[:l] == s[-l:]:
            print(s[:l])
            return

    print('Just a legend')

t0 = time.time()
solve_zscore(s)
print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 25)))
# s = ''.join(s) + s[0]

MOD = 10**9+7
N = len(s)

# t0 = time.time()

@lru_cache(maxsize=None)
def pow(a, b):
    if a == 1 or b == 0:
        return 1

    c = pow(a, b//2)
    if b % 2 == 0:
        return (c*c) % MOD
    else:
        return (c*c*a) % MOD

# print(time.time() - t0)
ha, hb = 0, 0
possible = []
pre = []
x = 1
for i, v in enumerate(s):
    u = s[N-i-1]
    ha = (ha * 26 + ord(v) - ord('a')) % MOD
    hb = ((ord(u) - ord('a')) * x + hb) % MOD
    x = (x * 26) % MOD
    if ha == hb:
        possible.append((i+1))
# print(pre)
# print(suf)

# print(possible)
# print(time.time() - t0)

def check(m):
    l = possible[m]
    t = s.find(s[:l], 1)
    return t > 0 and t != N-l

lo, hi = 0, len(possible)
while lo <= hi:
    m = (lo + hi) // 2
    if check(m):
        lo = m + 1
    else:
        hi = m - 1

print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

MOD = 10**9+7
N = len(s)

# print('starting...')
# t0 = time.time()

@lru_cache(maxsize=None)
def pow(a, b):
    if a == 1 or b == 0:
        return 1

    c = pow(a, b//2)
    if b % 2 == 0:
        return (c*c) % MOD
    else:
        return (c*c*a) % MOD

# print(time.time() - t0)
ha, hb = 0, 0
possible = []
x, oa = 1, ord('a')
w = [ord(v)-oa for v in s]
for i, v in enumerate(w):
    ha = (ha * 26 + v) % MOD
    hb = (w[N-i-1] * x + hb) % MOD
    x = (x * 26) % MOD
    if ha == hb:
        possible.append((i+1))
# print(pre)
# print(suf)

# print(possible)
# print(time.time() - t0)
#
# print(len(possible))

def check(m):
    l = possible[m]
    t = s.find(s[:l], 1)
    return t > 0 and t != N-l

lo, hi = 0, len(possible)
while lo <= hi:
    m = (lo + hi) // 2
    if check(m):
        lo = m + 1
    else:
        hi = m - 1

# print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

def solve_hash(s):
    print('starting...')
    t0 = time.time()
    MOD = 10**9+7
    N = len(s)
    ha, hb = 0, 0
    possible = []
    x, oa = 1, ord('a')
    w = [ord(v)-oa for v in s]
    for i, v in enumerate(w):
        ha = (ha * 26 + v) % MOD
        hb = (w[N-i-1] * x + hb) % MOD
        x = (x * 26) % MOD
        if ha == hb:
            possible.append((i+1))

    # print(possible)
    print(time.time() - t0)
    #
    # print(len(possible))

    def check(m):
        l = possible[m]
        t = s.find(s[:l], 1)
        return t > 0 and t != N-l

    lo, hi = 0, len(possible)
    while lo <= hi:
        m = (lo + hi) // 2
        if check(m):
            lo = m + 1
        else:
            hi = m - 1

    # print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

    print(time.time() - t0)

def solve_zscore(s):
    """
    https://cp-algorithms.com/string/z-function.html
    """
    z, maxl = [0] * len(s), 0
    i, l, r, n = 1, 0, 0, len(s)
    while i < n:
        if i <= r:
            z[i] = min(r-i+1, z[i-l])

        while i + z[i] < n and s[z[i]] == s[z[i] + i]:
            z[i] += 1

        if i + z[i] - 1 > r:
            l, r = i, i + z[i] - 1

        if i + z[i] == n:
            if z[i] < maxl:
                print(s[:z[i]])
                return
        maxl = max(maxl, z[i])
        i += 1

    print('Just a legend')

# t0 = time.time()
solve_zscore(s)
# print(time.time() - t0)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 12/25/19

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
from functools import lru_cache

# s = 'a' * (10**6)
s = input()
# import random
# s = []
# for i in range(10**6):
#     s.append(chr(ord('a') + random.randint(0, 5)))
# s = ''.join(s) + s[0]

MOD = 10**9+7
N = len(s)

# print('starting...')
# t0 = time.time()

@lru_cache(maxsize=None)
def pow(a, b):
    if a == 1 or b == 0:
        return 1

    c = pow(a, b//2)
    if b % 2 == 0:
        return (c*c) % MOD
    else:
        return (c*c*a) % MOD

# print(time.time() - t0)
ha, hb = 0, 0
possible = []
x, oa = 1, ord('a')
w = [ord(v)-oa for v in s]
for i, v in enumerate(w):
    ha = (ha * 26 + v) % MOD
    hb = (w[N-i-1] * x + hb) % MOD
    x = (x * 26) % MOD
    if ha == hb:
        possible.append((i+1))
# print(pre)
# print(suf)

# print(possible)
# print(time.time() - t0)
#
# print(len(possible))

def check(m):
    l = possible[m]
    t = s.find(s[:l], 1)
    return t > 0 and t != N-l

lo, hi = 0, len(possible)
while lo <= hi:
    m = (lo + hi) // 2
    if check(m):
        lo = m + 1
    else:
        hi = m - 1

print(s[:possible[hi]] if hi >= 0 else 'Just a legend')

# print(time.time() - t0)


def KMPPreprocess(p):
    m = len(p)
    kmp = [0] * m
    i = 1
    j = 0
    while i < m:
        if p[i] == p[j]:
            j += 1
            kmp[i] = j
            i += 1
        else:
            if j == 0:
                kmp[i] = j
                i += 1
            else:
                j = kmp[j - 1]
    return kmp

s = input()
kmp = KMPPreprocess(s)
res = 0

for i in range(1, len(s) - 1):
    if kmp[i] != 0:
        if kmp[i] == kmp[-1]:
            res = kmp[i]
            break
if res == 0 and kmp[-1] != 0 and kmp[kmp[-1] - 1] != 0:
    res = kmp[kmp[-1] - 1]

print(s[:res] if res > 0 else 'Just a legend')


def KMPPreprocess(p):
    m = len(p)
    kmp = [0] * m
    i = 1
    j = 0
    while i < m:
        if p[i] == p[j]:
            j += 1
            kmp[i] = j
            i += 1
        else:
            if j == 0:
                kmp[i] = j
                i += 1
            else:
                j = kmp[j - 1]
    return kmp

s = input()
kmp = KMPPreprocess(s)
res = 0
if kmp[-1] != 0 and kmp[kmp[-1] - 1] != 0:
    res = kmp[kmp[-1] - 1]
else:
    for i in range(1, len(s) - 1):
        if kmp[i] != 0:
            if kmp[i] == kmp[-1]:
                res = kmp[i]
                break
print(s[:res] if res > 0 else 'Just a legend')


def KMPPreprocess(p):
    m = len(p)
    kmp = [0] * m
    i = 1
    j = 0
    while i < m:
        if p[i] == p[j]:
            j += 1
            kmp[i] = j
            i += 1
        else:
            if j == 0:
                kmp[i] = j
                i += 1
            else:
                j = kmp[j - 1]
    return kmp

s = input()
kmp = KMPPreprocess(s)
res = 0
if kmp[-1] != 0 and kmp[kmp[-1] - 1] != 0:
    red = kmp[kmp[-1] - 1]
else:
    for i in range(1, len(s) - 1):
        if kmp[i] != 0:
            if kmp[i] == kmp[-1]:
                res = kmp[i]
                break
print(s[:res] if res > 0 else 'Just a legend')


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    lps[0] = 0
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
val3 = dp[dp[len(s)-1]-1]
maxx = -1
for i in range(len(s)-2,0,-1):
    if dp[i] == val:
        # ans = s[:val]
        maxx = val

    elif dp[i] != 0:
        val2 = dp[i]
        if val2 == val3:
            # ans = s[:val2]
            maxx = max(maxx,val)

ans = s[:maxx]
if maxx != -1:
    print(ans)
else:
    print("Just a legend")


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    lps[0] = 0
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
val3 = dp[dp[len(s)-1]-1]
maxx = -1
for i in range(len(s)-2,0,-1):
    if dp[i] == val:
        # ans = s[:val]
        maxx = val

    elif dp[i] != 0:
        val2 = dp[i]
        if val2 == val3:
            # ans = s[:val2]
            maxx = max(maxx,val)

ans = s[:maxx]
if ans != "":
    print(ans)
else:
    print("Just a legend")


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    lps[0] = 0
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
val3 = dp[dp[len(s)-1]-1]
maxx = -1
for i in range(len(s)-2,0,-1):
    if dp[i] == val and val != 0:
        # ans = s[:val]
        maxx = val

    elif dp[i] != 0:
        val2 = dp[i]
        if val2 == val3:
            # ans = s[:val2]
            maxx = max(maxx,val2)

ans = s[:maxx]
if maxx != -1:
    print(ans)
else:
    print("Just a legend")


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    lps[0] = 0
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
val3 = dp[dp[len(s)-1]-1]
maxx = -1
for i in range(len(s)-2,0,-1):
    if dp[i] == val:
        # ans = s[:val]
        maxx = val

    elif dp[i] != 0:
        val2 = dp[i]
        if val2 == val3:
            # ans = s[:val2]
            maxx = max(maxx,val2)

ans = s[:maxx]
if maxx != -1:
    print(ans)
else:
    print("Just a legend")


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    lps[0] = 0
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
val3 = dp[dp[len(s)-1]-1]
for i in range(len(s)-2,0,-1):
    if dp[i] == val:
        ans = s[:val]
        break
    elif dp[i] != 0:
        val2 = dp[i]
        if val2 == val3:
            ans = s[:val2]
            break
if ans != "":
    print(ans)
else:
    print("Just a legend")


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def computeLPSArray(pat):
    val = 0
    lps = [0]*len(pat)
    # lps[0]
    i = 1
    while i < len(pat):
        if pat[i]== pat[val]:
            val += 1
            lps[i] = val
            i += 1
        else:
            if val != 0:
                val = lps[val-1]
            else:
                lps[i] = 0
                i += 1
    return lps

s = ri()
dp = computeLPSArray(s)
# print(dp)
val = dp[len(s)-1]
ans = ""
for i in range(len(s)-2,0,-1):
    if dp[i] == val:
        ans = s[:val]
        break
    elif dp[i] != 0:
        val2 = dp[dp[i]-1]
        if val2 != 0:
            ans = s[:val2]
            break
if ans != "":
    print(ans)
else:
    print("Just a legend")


s = input()
t = [0]
i, length = 1, 0

while i < len(s):
    if s[i] == s[length]:
        length += 1
        t.append( length)
        i += 1
    else:
        if length == 0:
            t.append(length)
            i += 1
        else:
            length = t[length-1]
if t[-1] != 0:
    if len([a for a in t if a == t[-1]]) >= 2:
        print(s[:t[-1]])
    else:
        q = t[t[-1]]
        if q != 0:
            print(s[:q])
        else:
            print('Just a legend')
else:
    print('Just a legend')


s = input()
t = [0]
i, length = 1, 0

while i < len(s):
    if s[i] == s[length]:
        length += 1
        t.append( length)
        i += 1
    else:
        if length == 0:
            t.append(length)
            i += 1
        else:
            length = t[length-1]
#print(t)
if t[-1] != 0:
    if len([a for a in t if a == t[-1]]) >= 2:
        print(s[:t[-1]])
    else:
        q = t[t[-1]-1]
        if q != 0:
            print(s[:q])
        else:
            print('Just a legend')
else:
    print('Just a legend')


s=input()
n=len(s)
p=[-1]*n
mark=[False]*n
q=-1
for i in range(1,n):
    while q>=0 and s[i]!=s[q+1]:
        q=p[q]
    if s[i] == s[q + 1]:
        q += 1
        p[i] = q
    if q>=0 and i<n-1:
        mark[q]=True
#print(p)
q=p[n-1]
while q>=0:
    if s[0:q+1]==s[n-q-1:] and mark[q]:
        print(s[0:q+1])
        exit()
    q=p[q]
print('Just a legend')


s=input()
n=len(s)
p=[-1]*n
exist=[False]*n
q=-1
for i in range(1,n):
    while q>=0 and s[i]!=s[q+1]:
        q=p[q]
    if s[i] == s[q + 1]:
        q += 1
        p[i] = q
#print(p)
q=p[n-1]
while q>=0:
    if s[0:q+1]==s[n-q-1:] and s[0:q+1] in s[1:n-1]:
        print(s[0:q+1])
        exit()
    q=p[q]
print('Just a legend')


s=input()
n=len(s)
p=[-1]*n
c=[0]*n
q=-1
for i in range(1,n):
    while q>=0 and s[i]!=s[q+1]:
        q=p[q]
    if s[i] == s[q + 1]:
        q += 1
        p[i] = q
    j=q
    while j>=0:
        c[j]+=1
        j=p[j]
#print(p)
#print(c)
q=p[n-1]
while q>=0:
    if s[0:q+1]==s[n-q-1:] and c[q]>1:
        print(s[0:q+1])
        exit()
    q=p[q]
print('Just a legend')


s=input()
n=len(s)
p=[-1]*n
c=[0]*n
q=-1
for i in range(1,n):
    while q>=0 and s[i]!=s[q+1]:
        q=p[q]
    if s[i] == s[q + 1]:
        q += 1
        p[i] = q
    if q>=0:
        c[q]+=1
#print(p)
#print(c)
q=p[n-1]
while q>=0:
    if s[0:q+1]==s[n-q-1:] and c[q]>1:
        print(s[0:q+1])
        exit()
    q=p[q]
print('Just a legend')


n=input()
hm=[0]*(len(n)+1)
p=31
m=len(n)
mod=10**9+9
pow=[0]*(m+1)
pow[0]=1
for i in range(1,m):
    pow[i]=(pow[i-1]*p)%mod
hm[0]=1*(ord(n[0])-ord('a')+1)
m=len(n)
s=0
e=0
ans=[]
a=0
#print((pow[8]*24+(98815946))%mod)
#print(binary_exp(12,3))
for i in range(1,m):
    x=ord(n[i])-ord('a')+1
    hm[i]=(hm[i-1]%mod+(pow[i]*x)%mod)%mod
#print(hm)
for j in range(0,m):

    a=hm[j]
    s=m-1-j
    e=m-1
    a=(hm[j]*(pow[s]))%mod

    b=(hm[e]-hm[s-1]+mod)%mod
    #print(a,b)
    if a==b:
        ans.append(j)
def check(idx):

    id=ans[idx]

    l=1
    r=id+1

    while(l<m and r<m):

        a=(hm[id]*pow[l])%mod
        b=(hm[r]-hm[l-1]+mod)%mod
        if(a==b and r!=m-1):
            return True
        l+=1
        r+=1
    return False
lo=0
hi=len(ans)
while(lo<=hi):
    mi=(lo+hi)//2
    if(check(mi)):

        lo=mi+1
    else:
        hi=mi-1
if(lo-1==-1):
    print("Just a legend")
else:
    print(n[:ans[lo-1]+1])


n=input()
def search(st,tar):
    x=len(tar)
    y=len(st)
    l=0
    r=x
    while(l<y and r<y):
        if(st[l:r]==tar):
            return True
        else:
            l+=1
            r+=1
    return False
low=1
high=10**6
m=len(n)
while(low<=high):
    mid=(low+high)//2
    #print(mid)
    if mid>=m:
        high=mid-1
        continue
    if(search(n[mid:m-mid],n[0:mid]) and n[m-mid:m]==n[0:mid]):
        #(mid)
        low=mid+1
    else:
        high=mid-1
if(low-1==0):
    print("Just a legend")
else:
    print(n[:low-1])


n="aabaaabaaaaab"
hm=[0]*(len(n)+1)
p=31
m=len(n)
mod=10**9+9
pow=[0]*(m+1)
pow[0]=1
for i in range(1,m):
    pow[i]=(pow[i-1]*p)%mod
hm[0]=1*(ord(n[0])-ord('a')+1)
m=len(n)
s=0
e=0
ans=[]
a=0
#print((pow[8]*24+(98815946))%mod)
#print(binary_exp(12,3))
for i in range(1,m):
    x=ord(n[i])-ord('a')+1
    hm[i]=(hm[i-1]%mod+(pow[i]*x)%mod)%mod
#print(hm)
for j in range(0,m):

    a=hm[j]
    s=m-1-j
    e=m-1
    a=(hm[j]*(pow[s]))%mod

    b=(hm[e]-hm[s-1]+mod)%mod
    #print(a,b)
    if a==b:
        ans.append(j)
def check(idx):

    id=ans[idx]

    l=1
    r=id+1

    while(l<m and r<m):

        a=(hm[id]*pow[l])%mod
        b=(hm[r]-hm[l-1]+mod)%mod
        if(a==b and r!=m-1):
            return True
        l+=1
        r+=1
    return False
lo=0
hi=len(ans)
while(lo<=hi):
    mi=(lo+hi)//2
    if(check(mi)):

        lo=mi+1
    else:
        hi=mi-1
if(lo-1==-1):
    print("Just a legend")
else:
    print(n[:ans[lo-1]+1])


from collections import Counter
import sys
def alele(): return list(map(int, sys.stdin.readline().strip().split()))
def ilele(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
def computeLPSArray(pat, M, lps):
    len = 0
    lps[0]
    i = 1
    while i < M:
        if pat[i]== pat[len]:
            len += 1
            lps[i] = len
            i += 1
        else:
            if len != 0:
                len = lps[len-1]
            else:
                lps[i] = 0
                i += 1
text=input();n=len(text);lps=[0]*n;computeLPSArray(text,n,lps)#;print(lps)
t=lps[-1]
if lps.count(t)<2:
    t=lps[t-1]
print(text[:t] if t>0 else 'Just a legend')


from collections import Counter
import sys
def alele(): return list(map(int, sys.stdin.readline().strip().split()))
def ilele(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
def getZarr(string, z):
	n = len(string)
	l, r, k = 0, 0, 0
	for i in range(1, n):
		if i > r:
			l, r = i, i
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1
text=input();n=len(text);z=[0]*n;getZarr(text,z);#print(z)
if sum(z)==n*(n-1)//2:print(text[:n-2])
else:
    z=Counter(z);Ans=0
    for i in z.keys():
        if z[i]>=2:
            if i>Ans:Ans=i
    print(text[:Ans])


from collections import Counter
import sys
def alele(): return list(map(int, sys.stdin.readline().strip().split()))
def ilele(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
def getZarr(string, z):
	n = len(string)
	l, r, k = 0, 0, 0
	for i in range(1, n):
		if i > r:
			l, r = i, i
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1
text=input();n=len(text);z=[0]*n;getZarr(text,z);#print(z)
if sum(z)==n*(n-1)//2:print(text[:n-2])
else:
    A=Counter(z);Ans=0;flag=0;#print(z)
    for i in A.keys():
        if A[i]>=2 and z[-i]==i and i>0:
            flag=1
            if i>Ans:Ans=i
    print(text[:Ans]) if flag==1 else print('Just a legend')


s,k,l=input(),-1,[-1]
for c in s:
    while(k!=-1)and(s[k]!=c):
        k=l[k]
    k+=1
    l.append(k)
le=l[-1]
if l.count(le)<2:
    le=l[le]
print(s[:le] if le>0 else 'Just a legend')


s=input();c=-1;jaya=[-1]
for i in s:
    while(c!=-1)and(s[c]!=i):
        c=jaya[c]
    c+=1;jaya.append(c)
tot=jaya[-1]
if jaya.count(tot)<2:
    tot=jaya[tot]
print(s[:tot] if tot>0 else 'Just a legend')


import sys
input=sys.stdin.readline
s=input();i=1;n=len(s);flag=0;m=[];s1=s[::-1]
while i<n-2:
    t=s[:i];p=s1[:i][::-1]
    if t==p:flag=1;m.append(t)
    i+=1
if flag==0:print('Just a legend')
else:
    m=m[::-1];k=0;#print(m)
    for i in m:
        if i in s[1:n-2]:print(i);k=1;break
    if k==0: print('Just a legend')


import sys
input=sys.stdin.readline
s=input();i=1;n=len(s);flag=0;m=[];s1=s[::-1]
while i<n-2:
    t=s[:i];p=s1[:i][::-1];#print(t,p)
    if t==p:flag=1;m.append(t)
    i+=1
if flag==0:print('Just a legend')
else:
    m=m[::-1];k=0;#print(m)
    for i in m:
        if i in s[1:n-1]:print(i);k=1;break
    if k==0: print('Just a legend')


s=input();c=-1;jaya=[-1]
for i in s:
    while(c!=-1)and(s[c]!=i):
        c=jaya[c]
    c+=1;jaya.append(c)
tot=jaya[-1]
if jaya.count(tot)<2:
    tot=l[tot]
print(s[:tot] if tot>0 else 'Just a legend')


s,k,lps=input(),-1,[-1]
for c in s:
    while k!=-1 and s[k]!=c:
        k=lps[k]
    k+=1
    lps.append(k)
lenth=lps[-1]
if lps.count(lenth)<2:
    lenth=lps[lenth]
# print(lps)
print(s[:lenth] if lenth>0 else "Just a legend")


s,k,lps=input(),-1,[-1]
for c in s:
    while k!=-1 and s[k]!=c:
        k=lps[k]
    k+=1
    lps.append(k)
lenth=lps[-1]
if lps.count(lenth)<2:
    lenth=-1
print(s[:lenth] if lenth>0 else "Just a legend")


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1])) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * ord(s[n - l]) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    sub = s[:ls[m]]
    if sub in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]) and s.endswith(s[:ls[l]]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 12 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1]) - ord('a') + 1) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * (ord(s[n - l]) - ord('a') + 1) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1])) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * ord(s[n - l]) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1]) - ord('a') + 1) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * (ord(s[n - l]) - ord('a') + 1) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations, combinations
from sys import stdout

R = lambda: map(int, input().split())
s = input()
n = len(s)
z = [0] * n
l, r = 0, 0
for i in range(1, n):
    if i > r:
        k = i
        while k < n and s[k] == s[k - i]:
            k += 1
        l, r = i, k - 1
        z[l] = r - l + 1
    else:
        if i + z[i - l] <= r:
            z[i] = z[i - l]
        else:
            j = r + 1
            while j < n and s[j] == s[j - i]:
                j += 1
            l, r = i, j - 1
            z[i] = r - l + 1
sz = sorted(z[1:])
for l in range(n - 1, 0, -1):
    if z[n - l] == l and len(sz) - bisect_left(sz, l) >= 2:
        print(s[:l])
        exit(0)
print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 18 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1])) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * ord(s[n - l]) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1])) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * ord(s[n - l]) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    sub = s[:ls[m]]
    if (sub in s[1:n - 1]) and s.endswith(sub):
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (27 * px + ord(s[l - 1]) - ord('a') + 1) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * (ord(s[n - l]) - ord('a') + 1) + px) % lm
    bs = (bs * 27) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


R = lambda: map(int, input().split())
s = input()
n = len(s)
lm = 10 ** 9 + 7
ls = []
hss = set()
px = 0
for l in range(1, n):
    px = (26 * px + ord(s[l - 1]) - ord('a')) % lm
    hss.add(px)
px = 0
bs = 1
for l in range(1, n):
    px = (bs * (ord(s[n - l]) - ord('a')) + px) % lm
    bs = (bs * 26) % lm
    if px in hss:
        ls.append(l)
l, r = 0, len(ls) - 1
while l < r:
    m = (l + r + 1) // 2
    if s[:ls[m]] in s[1:n - 1]:
        l = m
    else:
        r = m - 1
if l < len(ls) and (s[:ls[l]] in s[1:n - 1]):
    print(s[:ls[l]])
else:
    print('Just a legend')


s = input()
i, n = 0, len(s)
p = [-1] + [0] * n
for j in range(1, n):
    while i + 1 and s[i] != s[j]: i = p[i]
    i += 1
    p[j + 1] = i
k = p.pop()
print(s[:k] if k and k in p else s[:p[k]] if p[k] > 0 else 'Just a legend')


# your code goes here
s=input()
le=0
for i in range(len(s)):

	if s[:i] in s[1:len(s)-1] and s[:i]==s[len(s)-i:] and i>le:
		le=i

if(le>0):
	print(s[:le])
else:
	print('Just a legend')


def getLPS(s1,l):
  lps=[0]*l
  i=1
  j=0
  while i<l:
    if s1[i]==s1[j]:
       lps[i]=j+1
       j+=1
       i+=1

    else:
      if j!=0:
        j=lps[j-1]
      else:
         lps[i]=0
         i+=1
  return lps
s=input()
n=len(s)
arr=getLPS(s,n)
lenth=arr[-1]
#print(arr)
#print(arr)
#print(lenth)
if arr.count(lenth)==1:
  lenth=arr[lenth-1]
 # print(lenth)
if lenth>0:
  #print(lenth)
  print(s[:lenth])
else:print('Just a legend')


import bisect
def ZAlgo(s):
    z=[0]*len(s)
    left=right=0
    for k in range (1,len(s)):
        if k > right:
            left=right=k
            while(right < len(s) and s[right] == s[right-left]):
                right+=1
            z[k]=right-left
            right-=1
        else:
            k1=k-left
            if z[k1] < right - k + 1:
                z[k]=z[k1]
            else:
                left=k
                while(right < len(s) and s[right] == s[right-left]):
                    right+=1
                z[k]=right-left
                right-=1
    return z
pat=input();M=len(pat)
z=ZAlgo(pat);c=1;suf=[];count=0;m=0
for i in range(len(z)):
    if z[i]>0:
        p=i
        break
##print (z)
##print (len(pat)-p)
suffix={}
for i in range(M-1,-1,-1):
    if z[i]==c and z[i]<len(pat)-p:
        suf.append(z[i])
        suffix[z[i]]=i
    c+=1
suf=sorted(suf)
#print (suffix)
if len(suf)>1:
    #print(pat[:suf[-2]])
    for i in range(len(z)):
        if z[i] not in suffix or suffix[z[i]]!=i:
            m=max(m,bisect.bisect_right(suf,z[i]))
    print (pat[:suf[m-1]])
elif len(suf)==1:
    for i in z:
        if i>=suf[0]:
            count+=1
    if count>=2:
        print (pat[:suf[0]])
    else:
        print ('Just a legend')
else:
    print ('Just a legend')


def longestPrefixSuffix(w,s):

    n = len(s)
    lps = [0] * n

    l = 0

    i = 1
    while (i < n):
        if (s[i] == s[l]):
            l = l + 1
            lps[i] = l
            i = i + 1

        else:

            if (l != 0):
                l = lps[l - 1]

            else:

                lps[i] = 0
                i = i + 1

    ans=0
    for i in range(w+1,n):
        if lps[i]==w:
            ans+=1

    return ans-1

# Driver program to test above function
n,w=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
des=""
for j in range(1,w):
    des+=str(b[j]-b[j-1])
des+="#"
for j in range(1,n):
    des+=str(a[j]-a[j-1])

if w==1:
    print(n)
else:
    print(longestPrefixSuffix(w-1,des))


def longestPrefixSuffix(s):
    global d
    n = len(s)
    lps = [0] * n  # lps[0] is always 0

    # length of the previous
    # longest prefix suffix
    l = 0
    m = 0

    # the loop calculates lps[i]
    # for i = 1 to n-1
    i = 1
    while (i < n):
        if (s[i] == s[l]):
            l = l + 1
            lps[i] = l
            i = i + 1

        else:

            # (pat[i] != pat[len])
            # This is tricky. Consider
            # the example. AAACAAAA
            # and i = 7. The idea is
            # similar to search step.
            if (l != 0):
                l = lps[l - 1]

                # Also, note that we do
                # not increment i here

            else:

                # if (len == 0)
                lps[i] = 0
                i = i + 1

    s = s[::-1]
    lps1 = [0] * n  # lps[0] is always 0

    # length of the previous
    # longest prefix suffix
    l = 0

    # the loop calculates lps[i]
    # for i = 1 to n-1
    i = 1
    while (i < n):
        if (s[i] == s[l]):
            l = l + 1
            lps1[i] = l
            i = i + 1

        else:

            # (pat[i] != pat[len])
            # This is tricky. Consider
            # the example. AAACAAAA
            # and i = 7. The idea is
            # similar to search step.
            if (l != 0):
                l = lps1[l - 1]

                # Also, note that we do
                # not increment i here

            else:

                # if (len == 0)
                lps1[i] = 0
                i = i + 1
    ans=0

    for i in range(n-1):
        if lps[i]==lps1[n-(i-lps[i]+1)-1]:
            ans=max(ans,lps[i])

    return ans

# Driver program to test above function
q = input()

l=longestPrefixSuffix(q)
if l==0:
    print("Just a legend")
else:
    print(q[:l])


def longestPrefixSuffix(s):
    global d
    n = len(s)
    lps = [0] * n  # lps[0] is always 0

    # length of the previous
    # longest prefix suffix
    l = 0
    m = 0

    # the loop calculates lps[i]
    # for i = 1 to n-1
    i = 1
    while (i < n):
        if (s[i] == s[l]):
            l = l + 1
            lps[i] = l
            i = i + 1

        else:

            # (pat[i] != pat[len])
            # This is tricky. Consider
            # the example. AAACAAAA
            # and i = 7. The idea is
            # similar to search step.
            if (l != 0):
                l = lps[l - 1]

                # Also, note that we do
                # not increment i here

            else:

                # if (len == 0)
                lps[i] = 0
                i = i + 1

    s = s[::-1]
    lps1 = [0] * n  # lps[0] is always 0

    # length of the previous
    # longest prefix suffix
    l = 0

    # the loop calculates lps[i]
    # for i = 1 to n-1
    i = 1
    while (i < n):
        if (s[i] == s[l]):
            l = l + 1
            lps1[i] = l
            i = i + 1

        else:

            # (pat[i] != pat[len])
            # This is tricky. Consider
            # the example. AAACAAAA
            # and i = 7. The idea is
            # similar to search step.
            if (l != 0):
                l = lps1[l - 1]

                # Also, note that we do
                # not increment i here

            else:

                # if (len == 0)
                lps1[i] = 0
                i = i + 1
    ans=0
    for i in range(n-1):
        ans=max(ans,min(lps[i],lps1[n-(i-lps[i]+1)-1]))

    return ans

# Driver program to test above function
q = input()

l=longestPrefixSuffix(q)
if l==0:
    print("Just a legend")
else:
    print(q[:l])


def subhash(l, r):
    global un_h
    global pw
    big = un_h[r]
    small = 0
    if l > 0:
        small = (un_h[l - 1] * pw[r - l + 1]) % mod
    return (big - small + mod) % mod

def HASH(st):
    global p
    global mod
    un_h = [0] * len(st)
    un_h[0] = ord(st[0])
    for i in range(1, len(st)):
        un_h[i] = (un_h[i - 1] * p + ord(st[i])) % mod
    return un_h

def hash2(st, hash3 = 0):
    global p
    global mod
    for i in range(len(st)):
        hash3 = (hash3 * p + ord(st[i])) % mod
    return hash3

p = 29
mod = 10 ** 9 + 7
str1 = input()
pw = [1] * (len(str1) + 1)
for i in range(1, len(pw)):
    pw[i] = pw[i - 1] * p % mod
un_h = HASH(str1)
ans = "Just a legend"
prefs = [0]
for z in range(0, len(str1) - 2):
    if (subhash(0, z)== subhash(len(str1) - 1 - z, len(str1) - 1)):
        prefs.append(z + 1)
r = len(prefs)
l = 0
while r - l != 1:
    m = (r + l) // 2
    hash1 = subhash(0, prefs[m] - 1)
    i = 1
    j = prefs[m]
    t = False
    while j < len(str1) - 1:
        H = subhash(i, j)
        if H == hash1:
            l = m
            t = True
            break
        i += 1
        j += 1
    if t == False:
        r = m
if prefs[l] == 0:
    print(ans)
else:
    print(str1[:prefs[l]])


import sys, math
readline = sys.stdin.readline
s = readline().split()[0]
def z_Func(s):
    n = len(s)
    l,r = 0,0
    z = [0 for _ in range(n)]
    for i in range(1,n):
        if i <= r:
            z[i] = min(r - i + 1,z[i - l])
        while i + z[i] < n and s[z[i]] == s[i + z[i]]:
            z[i] += 1
        if i + z[i] - 1 > r:
            l,r = i,i + z[i] - 1
    return z

tp = z_Func(s)
j = 0
mySet = set()
for i in range(len(tp)):
    if tp[i] == len(tp) - i and tp[i] in mySet:
        j = i
        break
    mySet.add(tp[i])
if j:
    print(s[:len(tp) - j])
else:
    print('Just a legend')


import sys, math
readline = sys.stdin.readline
s = readline().split()[0]
def z_Func(s):
    n = len(s)
    l,r = 0,0
    z = [0 for _ in range(n)]
    for i in range(1,n):
        if i <= r:
            z[i] = min(r - i + 1,z[i - l])
        while i + z[i] < n and s[z[i]] == s[i + z[i]]:
            z[i] += 1
        if i + z[i] - 1 > r:
            l,r = i,i + z[i] - 1
    return z

tp = z_Func(s)
j = 0
m = 0
for i in range(len(tp)):
    if tp[i] == len(tp) - i and tp[i] <= m:
        j = i
        break
    m = max(m,tp[i])
if j:
    print(s[:len(tp) - j])
else:
    print('Just a legend')


def Zarr(pat,text):
    s=pat+"/"+text;
    z=[0 for i in range(len(s))]
    L=0;R=0;n=len(s);
    for i in range(1,len(s)):
        if i>R:
            L=R=i
            while R<n and s[R-L]==s[R]:
                R+=1
            z[i]=R-L
            R-=1
        elif z[i-L]+i<=R:
            z[i]=z[i-L]
        else:
            L=i
            while R<n and s[R-L]==s[R]:
                R+=1
            z[i]=R-L
            R-=1
    dp=[0 for i in range(1000006)]
    ans=-1
    for i in range(len(pat)+2,len(s)):
        dp[z[i]]+=1
    for i in range(len(dp)-2,-1,-1):
        dp[i]+=dp[i+1]
    for i in range(len(pat)+2,len(s)):
        if i+z[i]==len(s) and dp[z[i]]>1 and z[i]>ans:
            ans=z[i]
    if ans==-1:
        print("Just a legend")
    else:
        print(pat[0:ans])

from sys import stdin
text=stdin.readline().strip()
Zarr(text,text)


def Zarr(pat,text):
    s=pat+"/"+text;
    z=[0 for i in range(len(s))]
    L=0;R=0;n=len(s);
    for i in range(1,len(s)):
        if i>R:
            L=R=i
            while R<n and s[R-L]==s[R]:
                R+=1
            z[i]=R-L
            R-=1
        elif z[i-L]+i<=R:
            z[i]=z[i-L]
        else:
            L=i
            while R<n and s[R-L]==s[R]:
                R+=1
            z[i]=R-L
            R-=1
    dp=[0 for i in range(1000006)]
    ans=-1
    for i in range(len(pat)+2,len(s)):
        dp[z[i]]+=1
        if i+z[i]==len(s) and dp[z[i]]>1 and z[i]>ans:
            ans=z[i]
    if ans==-1:
        print("Just a legend")
    else:
        print(pat[0:ans])

from sys import stdin
text=stdin.readline().strip()
Zarr(text,text)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

# sys.setrecursionlimit(10**6)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def z_algorithm(s):
    sl = len(s)
    a = [0] * sl
    a[0] = sl
    i = 1
    j = 0
    while i < sl:
        while i + j < sl and s[j] == s[i + j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < sl and k + a[k] < j:
            a[i + k] = a[k]
            k += 1

        i += k
        j -= k

    return a

def main():
    t = 1

    rr = []
    for _ in range(t):
        s = S()

        sl = len(s)
        z = z_algorithm(s)
        r = 0
        u = 0
        for i in range(1,len(s)):
            t = z[i]
            if i + t == sl and u >= t:
                r = t
                break

            if u < t:
                u = t

        rr.append(IF(r==0, "Just a legend", s[:r]))

    return JA(rr, "\n")

print(main())


s = input()
def count_unique_substring(s):
    n = len(s)
    p = 31
    m = 10**9 + 9
    p_pow = [1]
    for i in range(1,n):
        p_pow.append((p_pow[i-1]*p)%m)
    hash = [0]
    count = 0
    flag=0
    for i in range(n):
        hash.append(( hash[i] + (ord(s[i])-ord('a')+1) * p_pow[i]) % m)
    for l in range(n,3,-1):
        c_1 = (hash[ l] + m - hash[0]) % m
        c_1 = c_1 * p_pow[n - 1] % m
        c_2 = (hash[n-l + l] + m - hash[n-l]) % m
        c_2 = c_2 * p_pow[l - 1] % m
        if c_1 == c_2:
            for i in range(1,n-l):
                c_h = (hash[i+l] + m - hash[i]) % m
                c_h = c_h * p_pow[n-i-1]%m
                if c_h == c_2:
                    return (s[i:i+l])

t = count_unique_substring(s)
if t:
    print(t)
else:
    print('Just a legend')


s = input()
def count_unique_substring(s):
    n = len(s)
    p = 31
    m = 10**9 + 9
    p_pow = [1]
    for i in range(1,n):
        p_pow.append((p_pow[i-1]*p)%m)
    hash = [0]
    count = 0
    flag=0
    for i in range(n):
        hash.append(( hash[i] + (ord(s[i])-ord('a')+1) * p_pow[i]) % m)
    for l in range(n,0,-1):
        c_1 = (hash[ l] + m - hash[0]) % m
        c_1 = c_1 * p_pow[n - 1] % m
        c_2 = (hash[n-l + l] + m - hash[n-l]) % m
        c_2 = c_2 * p_pow[l - 1] % m
        if c_1 == c_2:
            for i in range(1,n-l):
                c_h = (hash[i+l] + m - hash[i]) % m
                c_h = c_h * p_pow[n-i-1]%m
                if c_h == c_2:
                    return (s[i:i+l])

t = count_unique_substring(s)
if t:
    print(t)
else:
    print('Just a legend')


s = input()
def count_unique_substring(s):
    n = len(s)
    p = 31
    m = 10**9 + 9
    p_pow = [1]
    for i in range(1,n):
        p_pow.append((p_pow[i-1]*p)%m)
    hash = [0]
    count = 0
    flag=0
    for i in range(n):
        hash.append(( hash[i] + (ord(s[i])-ord('a')+1) * p_pow[i]) % m)
    for l in range(n,2,-1):
        c_1 = (hash[ l] + m - hash[0]) % m
        c_1 = c_1 * p_pow[n - 1] % m
        c_2 = (hash[n-l + l] + m - hash[n-l]) % m
        c_2 = c_2 * p_pow[l - 1] % m
        if c_1 == c_2:
            for i in range(1,n-l):
                c_h = (hash[i+l] + m - hash[i]) % m
                c_h = c_h * p_pow[n-i-1]%m
                if c_h == c_2:
                    return (s[i:i+l])

t = count_unique_substring(s)
if t:
    print(t)
else:
    print('Just a legend')


s = input()
def count_unique_substring(s):
    n = len(s)
    p = 31
    m = 10**9 + 9
    p_pow = [1]
    for i in range(1,n):
        p_pow.append((p_pow[i-1]*p)%m)
    hash = [0]
    count = 0
    flag=0
    for i in range(n):
        hash.append(( hash[i] + (ord(s[i])-ord('a')+1) * p_pow[i]) % m)
    for l in range(1,n-1):
        c_1 = (hash[ l] + m - hash[0]) % m
        c_1 = c_1 * p_pow[n - 1] % m
        c_2 = (hash[n-l + l] + m - hash[n-l]) % m
        c_2 = c_2 * p_pow[l - 1] % m
        if c_1 == c_2:
            for i in range(1,n-l):
                c_h = (hash[i+l] + m - hash[i]) % m
                c_h = c_h * p_pow[n-i-1]%m
                if c_h == c_2:
                    return (s[i:i+l])

t = count_unique_substring(s)
if t:
    print(t)
else:
    print('Just a legend')


from sys import stdin

def findpass(s):
    arr = suff_array(s)
    n = len(s)
    maxidx = arr[n - 1]
    valid = False

    for i in range(n - 1):
        if arr[i] == maxidx:
            valid = True
            break

    if not valid:
        maxidx = arr[maxidx - 1]

    if maxidx == 0:
        return "Just a legend"
    return s[:maxidx]

def suff_array(s):
    n = len(s)
    table = [0] * n

    pos, i = 0, 1

    while i < n:
        if s[pos] == s[i]:
            table[i] = pos + 1
            pos += 1
            i += 1
        elif pos == 0:
            i += 1
        else:
            pos = table[pos - 1]

#    print(table)
    return table

if __name__ == "__main__":
    s = stdin.readline().strip()
    print(findpass(s))


from sys import stdin

def findpass(s):
    arr = suff_array(s)

    sufflen = arr[-1]
    if sufflen == 0:
        return "Just a legend"
    cnt = 2
    for i in range(1, len(s) - 1):
        if cnt == 3:
            break
        if arr[i] == sufflen:
            cnt += 1

    if cnt < 3:
        return "Just a legend"

    return s[:sufflen]

def suff_array(s):
    n = len(s)
    table = [0] * n

    pos, i = 0, 1

    while i < n:
        if s[pos] == s[i]:
            table[i] = pos + 1
            pos += 1
            i += 1
        elif pos == 0:
            i += 1
        else:
            pos = table[pos - 1]

    return table

if __name__ == "__main__":
    s = stdin.readline().strip()
    print(findpass(s))


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>

#define MAXA 50000000
#define MOD 1000000007

using namespace std;

typedef map<int, int> MAP;

char arr[MAXA],*ptr;
long long ret,n,m,k;

int alF[100005],boF[100005];
int aloc,bloc;

MAP diff;
MAP ::iterator it_m;

inline long long get_int()
{
    ret =0;
    while ( !(*ptr >= '0' && *ptr <= '9'))
        ptr++;
    while (*ptr >= '0' && *ptr<= '9') {
        ret = ret*10 + (*ptr - '0');
        ptr++;
    }
    return ret;
}

int main()
{
    fread(arr,sizeof(char),MAXA,stdin);
    ptr = arr;
    n = get_int();
    m = get_int();
    k = get_int();
    int alice = 0,bob = 0;
    long long typeOfFish;

    for(int xx =0;xx< n;xx++){
        typeOfFish = get_int();
        alF[xx] = typeOfFish;
        it_m = diff.find(typeOfFish);
        if(it_m == diff.end())
            diff[typeOfFish] = 1;
        else
            (it_m->second)++;
    }
    for(int xx =0;xx< m;xx++){
        typeOfFish = get_int();
        boF[xx] = typeOfFish;
        it_m = diff.find(typeOfFish);
        if(it_m == diff.end())
            diff[typeOfFish] = -1;
        else
            (it_m->second)--;
    }

    aloc = 0;
    alice = 0;
    bob =0;
    bloc = 0;
    for(it_m = diff.begin();it_m != diff.end(); it_m++){
        if(it_m->second < 0 ){
            int temp = -(it_m->second);
            for(int xx =0;xx<temp;xx++)
                boF[bloc++] = it_m->first;
            bob++;
        }
        if(it_m->second > 0 ){
            int temp = (it_m->second);
            for(int xx =0;xx<temp;xx++)
                alF[aloc++] = it_m->first;

            alice++;
        }
    }
    int gobble = 0;
    if(aloc > bloc)
        cout << "YES";
    else if(aloc < bloc){
        for(int xx =0;xx<bloc;xx++)
        {
            for(int yy =0;yy<aloc;yy++){
                if(boF[xx] > alF[yy]){
                    gobble++;
                    alF[yy] = 99999999;
                    break;
                }
            }
        }
        if(gobble < aloc)
            cout << "YES";
        else
            cout << "YES";
    }
    else if(bloc == aloc){
        for(int xx =0;xx<bloc;xx++)
        {
            for(int yy =0;yy<aloc;yy++){
                if(boF[xx] > alF[yy]){
                    gobble++;
                    alF[yy] = 99999999;
                    break;
                }
            }
        }
        if(gobble < aloc)
            cout << "YES";
        else
            cout << "NO";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>

#define MAXA 50000000
#define MOD 1000000007

using namespace std;

typedef map<int, int> MAP;

char arr[MAXA],*ptr;
long long ret,n,m,k;

int alF[100005],boF[100005];
int aloc,bloc;

MAP diff;
MAP ::iterator it_m;

inline long long get_int()
{
    ret =0;
    while ( !(*ptr >= '0' && *ptr <= '9'))
        ptr++;
    while (*ptr >= '0' && *ptr<= '9') {
        ret = ret*10 + (*ptr - '0');
        ptr++;
    }
    return ret;
}

int main()
{
    fread(arr,sizeof(char),MAXA,stdin);
    ptr = arr;
    n = get_int();
    m = get_int();
    k = get_int();
    int alice = 0,bob = 0;
    long long typeOfFish;

    for(int xx =0;xx< n;xx++){
        typeOfFish = get_int();
        alF[xx] = typeOfFish;
        it_m = diff.find(typeOfFish);
        if(it_m == diff.end())
            diff[typeOfFish] = 1;
        else
            (it_m->second)++;
    }
    for(int xx =0;xx< m;xx++){
        typeOfFish = get_int();
        boF[xx] = typeOfFish;
        it_m = diff.find(typeOfFish);
        if(it_m == diff.end())
            diff[typeOfFish] = -1;
        else
            (it_m->second)--;
    }

    aloc = 0;
    alice = 0;
    bob =0;
    bloc = 0;
    for(it_m = diff.begin();it_m != diff.end(); it_m++){
        if(it_m->second < 0 ){
            int temp = -(it_m->second);
            for(int xx =0;xx<temp;xx++)
                boF[bloc++] = it_m->first;
            bob++;
        }
        if(it_m->second > 0 ){
            int temp = (it_m->second);
            for(int xx =0;xx<temp;xx++)
                alF[aloc++] = it_m->first;

            alice++;
        }
    }
    int gobble = 0;
    if(aloc > bloc)
        cout << "YES";
    else if(aloc < bloc){
        for(int xx =0;xx<bloc;xx++)
        {
            for(int yy =0;yy<aloc;yy++){
                if(boF[xx] > alF[yy]){
                    gobble++;
                    alF[yy] = 99999999;
                    break;
                }
            }
        }
        if(gobble < aloc)
            cout << "YES";
        else
            cout << "NO";
    }
    else if(bloc == aloc){
        for(int xx =0;xx<bloc;xx++)
        {
            for(int yy =0;yy<aloc;yy++){
                if(boF[xx] > alF[yy]){
                    gobble++;
                    alF[yy] = 99999999;
                    break;
                }
            }
        }
        if(gobble < aloc)
            cout << "YES";
        else
            cout << "YES";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>

#define MAXA 50000000
#define MOD 1000000007

using namespace std;

typedef map<int, int> MAP;

char arr[MAXA],*ptr;
long long ret,n,m,k;

int alF[100005],boF[100000];
int aloc,bloc;

MAP diff;
MAP ::iterator it_m;

inline long long get_int()
{
	ret =0;
	while ( !(*ptr >= '0' && *ptr <= '9'))
		ptr++;
	while (*ptr >= '0' && *ptr<= '9') {
		ret = ret*10 + (*ptr - '0');
		ptr++;
	}
	return ret;
}

int main()
{
	fread(arr,sizeof(char),MAXA,stdin);
	ptr = arr;
	n = get_int();
	m = get_int();
	k = get_int();
	int alice = 0,bob = 0;
	long long typeOfFish;

	for(int xx =0;xx< n;xx++){
		typeOfFish = get_int();
		alF[xx] = typeOfFish;
		it_m = diff.find(typeOfFish);
		if(it_m == diff.end())
			diff[typeOfFish] = 1;
		else
			(it_m->second)++;
	}
	for(int xx =0;xx< m;xx++){
		typeOfFish = get_int();
		boF[xx] = typeOfFish;
		it_m = diff.find(typeOfFish);
		if(it_m == diff.end())
			diff[typeOfFish] = -1;
		else
			(it_m->second)--;
	}

	aloc = 0;
	alice = 0;
	bob =0;
	bloc = 0;
	for(it_m = diff.begin();it_m != diff.end(); it_m++){
		if(it_m->second < 0 ){
			int temp = -(it_m->second);
			for(int xx =0;xx<temp;xx++)
				boF[bloc++] = it_m->first;
			bob++;
		}
		if(it_m->second > 0 ){
			int temp = (it_m->second);
			for(int xx =0;xx<temp;xx++)
				alF[aloc++] = it_m->first;

			alice++;
		}
	}
	int gobble = 0;
	if(aloc > bloc)
		cout << "YES";
	else if(aloc < bloc){
		for(int xx =0;xx<bloc;xx++)
		{
			for(int yy =0;yy<aloc;yy++){
				if(boF[xx] > alF[yy]){
					gobble++;
					alF[yy] = 99999999;
					break;
				}
			}
		}
		if(gobble == 0)
			cout << "YES";
		else
			cout << "NO";
	}
	else if(bloc == aloc){
		for(int xx =0;xx<bloc;xx++)
		{
			for(int yy =0;yy<aloc;yy++){
				if(boF[xx] > alF[yy]){
					gobble++;
					alF[yy] = 99999999;
					break;
				}
			}
		}
		if(gobble < aloc)
			cout << "YES";
		else
			cout << "NO";
	}
	return 0;
}