#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e9 + 7;
const int N = (int)1e6 + 7;
int p[N];
int cnt[N];
void prefix_calc(string &s) {
  int n = s.size();
  int j, i;
  p[0] = -1;
  for (i = 1; i < n; i++) {
    j = i - 1;
    while (j != -1 && s[p[j] + 1] != s[i]) j = p[j];
    if (j != -1)
      p[i] = p[j] + 1;
    else
      p[i] = -1;
  }
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int i;
  prefix_calc(s);
  int x = p[n - 1];
  if (x == -1) {
    cout << "Just a legend" << '\n';
    return 0;
  }
  for (i = x + 1; i < n - 1; i++) {
    if (p[i] >= x) {
      cout << s.substr(0, x + 1) << '\n';
      return 0;
    }
  }
  x = p[x];
  if (x == -1) {
    cout << "Just a legend" << '\n';
    return 0;
  }
  cout << s.substr(0, x + 1) << '\n';
}
