#include <bits/stdc++.h>
using namespace std;
void task() {
  string str;
  cin >> str;
  int l = 0;
  int r = 0;
  vector<int> z(str.length(), 0);
  for (int i = 1; i < str.length(); i++) {
    if (r > i) {
      z[i] = min(z[i - l], r - i);
    }
    while (i + z[i] < str.length() && str[z[i]] == str[i + z[i]]) {
      z[i]++;
    }
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
  int maxlen = -1;
  int ans = -1;
  for (int i = 0; i < str.length() && ans == -1; i++) {
    if (z[i] != 0) {
      if (i + z[i] == str.length() && maxlen >= z[i]) {
        ans = z[i];
      } else {
        maxlen = max(z[i], maxlen);
      }
    }
  }
  if (ans == -1) {
    cout << "Just a legend" << endl;
  }
  for (int i = str.length() - ans; i < str.length(); i++) {
    cout << str[i];
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  task();
  return 0;
}
