#include <bits/stdc++.h>
using namespace std;
int p[1000005];
void calc_pass(string pass) {
  int l = 0, r = 0, m, x = pass.size();
  for (int i = 1; i < x; i++) {
    if (i > r) {
      l = r = i;
      while (r < x and pass[r] == pass[r - l]) {
        r++;
      }
      p[i] = r - l;
      r--;
    } else {
      m = i - l;
      if (p[m] < r - i + 1)
        p[i] = p[m];
      else {
        l = i;
        while (r < x and pass[r] == pass[r - l]) {
          r++;
        }
        p[i] = r - l;
        r--;
      }
    }
  }
}
int main() {
  string pass;
  cin >> pass;
  int x = pass.size();
  calc_pass(pass);
  vector<int> ls, ms;
  for (int i = x - 1; i > 0; i--) {
    if (p[i] > 0 and i + p[i] == x) ls.push_back(p[i]);
  }
  int mx = 0;
  for (int i = 1; i < x - 1; i++) {
    if (i + p[i] < x)
      mx = max(mx, p[i]);
    else
      mx = max(mx, p[i] - 1);
  }
  int rs = 0;
  for (int i = 0; i < (int)ls.size(); i++) {
    if (ls[i] <= mx) rs = ls[i];
  }
  if (rs) {
    string ss = pass.substr(0, rs);
    puts(ss.c_str());
  } else
    puts("Just a legend");
}
