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