#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e6 + 7;
string s;
int p[MaxN], deg[MaxN], H[MaxN], x = 31, Sum;
void v() {
  deg[0] = 1;
  for (int i = 1; i <= s.size(); i++) deg[i] = deg[i - 1] * x;
  H[0] = 0;
  H[1] = s[0];
  for (int i = 2; i <= s.size(); i++) H[i] = H[i - 1] * x + s[i - 1];
}
int Find(int L, int R) { return H[R] - H[L - 1] * deg[R - L + 1]; }
int main() {
  cin >> s;
  v();
  for (int i = 1; i < s.size(); i++) {
    int k = p[i - 1];
    while (s[i] != s[k] && k > 0) k = p[k - 1];
    if (s[i] == s[k]) k++;
    p[i] = k;
    if (k > Sum && i != s.size() - 1)
      if (Find(1, k) == Find(s.size() - k + 1, s.size())) Sum = k;
  }
  if (Sum > 0)
    cout << s.substr(0, Sum), exit(0);
  else
    printf("Just a legend");
  return 0;
}
