#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size(), p;
  vector<int> pre(n, -1);
  for (int i = 1; i < n; i++) {
    p = i - 1;
    while (s[pre[p] + 1] != s[i]) {
      if (pre[p] == -1) {
        break;
      }
      p = pre[p];
    }
    if (s[pre[p] + 1] == s[i]) {
      pre[i] = pre[p] + 1;
    } else {
      pre[i] = -1;
    }
  }
  set<int> T;
  int i = pre[n - 1];
  while (i != -1) {
    T.insert(i + 1);
    i = pre[i];
  }
  int x = -1;
  for (int i = 1; i < n - 1; i++) {
    if (T.find(pre[i] + 1) != T.end()) {
      if (pre[i] + 1 > x) x = pre[i] + 1;
    }
  }
  if (x == -1)
    cout << "Just a legend\n";
  else {
    for (int i = 0; i < x; i++) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}
