#include <bits/stdc++.h>
using namespace std;
int kmp[1000007];
int i = 0;
void doit(string b) {
  kmp[0] = 0;
  int lth = b.length();
  for (int j = 1; j < (lth); j++) {
    while (b[j] != b[i] && i > 0) {
      i = kmp[i - 1];
    }
    if (b[j] == b[i]) {
      i++;
    } else {
      i = 0;
      if (b[j] == b[0]) {
        i++;
      }
    }
    kmp[j] = i;
  }
}
int main() {
  string a;
  cin >> a;
  doit(a);
  vector<int> check;
  int x, y;
  x = kmp[a.length() - 1];
  check.push_back(x);
  while (x > 0) {
    y = kmp[x - 1];
    check.push_back(y);
    x = y;
  }
  for (int j = 0; j < check.size(); j++) {
    x = check[j];
    if (x > 0) {
      for (int i = 1; i < (a.length() - 1); i++) {
        if (kmp[i] == x) {
          cout << a.substr(0, x);
          return 0;
          break;
        }
      }
    }
  }
  cout << "Just a legend";
  return 0;
}
