#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char a[N];
int p[N], n, sxl;
int main() {
  cin >> a + 1;
  n = strlen(a + 1);
  p[1] = 0;
  for (int i = 2, j = 0; i <= n; i++) {
    while (j && a[i] != a[j + 1]) j = p[j];
    if (a[i] == a[j + 1]) j++;
    p[i] = j;
    if (i != n) sxl = max(sxl, p[i]);
  }
  int x = p[n];
  if (x == 0) {
    cout << "Just a legend";
  } else {
    while (x > sxl) x = p[x];
    if (x == 0) {
      cout << "Just a legend";
      return 0;
    }
    for (int i = 2; i < n; i++)
      if (x == p[i]) {
        for (int j = i - p[i] + 1; j <= i; j++) cout << a[j];
        cout << endl;
        return 0;
      }
  }
  return 0;
}
