#include <bits/stdc++.h>
using namespace std;
long long p[1000005];
void kmp(string s) {
  long long n = -1;
  p[0] = -1;
  for (int i = 1; i < s.length(); i++) {
    while (n != -1 && s[i] != s[n + 1]) {
      n = p[n];
    }
    if (s[i] == s[n + 1]) {
      n++;
      p[i] = n;
    } else {
      p[i] = -1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  kmp(s);
  long long len = s.length();
  long long maxi = p[len - 1];
  long long found = p[maxi];
  if (maxi == -1) {
    found = -1;
  }
  for (int i = 1; i < len - 1; i++) {
    if (p[i] == maxi) {
      found = maxi;
    }
  }
  if (found == -1) {
    cout << "Just a legend" << endl;
  } else {
    cout << s.substr(0, found + 1) << endl;
  }
  return 0;
}
