#include <bits/stdc++.h>
using namespace std;
int Z[1000005], n, L = 0, R = 0;
string S;
vector<pair<int, int> > luu;
int main() {
  cin >> S;
  n = S.size();
  Z[0] = n;
  for (int i = 1; i < n; i++)
    if (i > R) {
      L = R = i;
      while (R < n && S[R] == S[R - L]) R++;
      Z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < n && S[R] == S[R - L]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  for (int i = 1; i < n; i++)
    if (Z[i] + i == n) luu.push_back(make_pair(i, Z[i]));
  if (luu.empty()) {
    cout << "Just a legend";
    return 0;
  }
  for (int i = 0; i < luu.size(); i++) {
    int kt = 0;
    for (int j = 1; j < luu[i].first; j++)
      if (Z[j] >= luu[i].second) {
        kt = 1;
        break;
      }
    if (kt == 1) {
      for (int j = 0; j < luu[i].second; j++) cout << S[j];
      return 0;
    }
  }
  cout << "Just a legend";
  return 0;
}
