#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> prefix(n);
  for (int i = 1, k = 0; i < n; i++) {
    while (k > 0 && s[k] != s[i]) k = prefix[k - 1];
    if (s[i] == s[k])
      prefix[i] = ++k;
    else
      prefix[i] = k;
  }
  int j = n, l;
  while (1) {
    l = j - 1;
    j = prefix[l];
    if (j == 0) break;
    for (int i = 0; i < (int)(n - 1); i++)
      if (prefix[i] >= j) {
        cout << s.substr(n - j) << endl;
        return 0;
      }
  }
  cout << "Just a legend\n";
  return 0;
}
