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