#include <bits/stdc++.h>
using namespace std;
int a[1000008];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  a[0] = 0;
  int i = 1, l = 0, n = s.length();
  while (i < n) {
    if (s[i] == s[l]) {
      l++;
      a[i] = l;
      i++;
    } else {
      if (l != 0) {
        l = a[l - 1];
      } else {
        a[i] = 0;
        i++;
      }
    }
  }
  if (a[n - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = 1; i <= n - 2; i++) {
    if (a[i] == a[n - 1]) {
      for (int i = 0; i < a[n - 1]; i++) {
        cout << s[i];
      }
      return 0;
    }
  }
  if (a[a[n - 1] - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = 1; i <= n - 2; i++) {
    if (a[i] == a[a[n - 1] - 1]) {
      for (int i = 0; i < a[a[n - 1] - 1]; i++) {
        cout << s[i];
      }
      return 0;
    }
  }
  cout << "Just a legend";
  return 0;
}
