#include <bits/stdc++.h>
using namespace std;
int main() {
  string pattern;
  cin >> pattern;
  long long int i, m, n, j;
  n = pattern.length();
  long long int dfa[n];
  memset(dfa, 0, sizeof(dfa));
  long long int x = 0;
  for (i = 1; i < n; i++) {
    if (pattern[i] == pattern[x])
      x++, dfa[i] = x;
    else if (x > 0) {
      x = dfa[x - 1];
      i--;
    }
  }
  for (i = 0; i < n - 1; i++)
    if (dfa[n - 1] > 0 && dfa[i] == dfa[n - 1]) {
      for (j = 0; j < dfa[n - 1]; j++) printf("%c", pattern[j]);
      cout << endl;
      return 0;
    }
  if (i == n - 1 && dfa[n - 1] > 0 && dfa[dfa[n - 1] - 1] > 0) {
    for (j = 0; j < dfa[dfa[n - 1] - 1]; j++) printf("%c", pattern[j]);
    cout << endl;
    return 0;
  } else if (i == n - 1)
    cout << "Just a legend\n";
  return 0;
}
