#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int n;
void KMPTable(char *w, int **t) {
  int i, j, *a;
  *t = new int[n];
  a = *t;
  a[0] = -1;
  a[1] = 0;
  i = 2;
  j = 0;
  while (i < n) {
    if (w[i - 1] == w[j])
      a[i++] = ++j;
    else if (j)
      j = a[j];
    else
      a[i++] = 0;
  }
}
int main() {
  cin >> s;
  n = strlen(s);
  s[n] = '$';
  s[n + 1] = 0;
  n++;
  int *t;
  KMPTable(s, &t);
  int i;
  if (t[n - 1] == 0) {
    cout << "Just a legend";
    return 0;
  }
  for (i = 1; i < n - 1; i++)
    if (t[i] == t[n - 1]) break;
  if (i < n - 1) {
    for (i = 0; i < t[n - 1]; i++) cout << s[i];
  } else {
    int j = t[n - 1];
    if (t[j] > 0) {
      for (i = 0; i < t[j]; i++) cout << s[i];
    } else
      cout << "Just a legend";
  }
  return 0;
}
