#include <bits/stdc++.h>
using namespace std;
string s;
const int MAXN = 1000500;
int z[MAXN];
int n;
vector<int> zs;
int main() {
  cin >> s;
  n = s.size();
  z[0] = 0;
  int mxne = 0;
  int i, j;
  int l, r;
  for (i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[z[i] + i]) ++z[i];
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
    if (i + z[i] < n)
      mxne = max(mxne, z[i]);
    else
      mxne = max(mxne, z[i] - 1);
  }
  int mxl = 0;
  int mxi;
  for ((i) = (1); (i) < (n); ++(i))
    if (i + z[i] == n && z[i] <= mxne) {
      for ((j) = (i); (j) < (n); ++(j)) printf("%c", s[j]);
      puts("");
      return 0;
    }
  puts("Just a legend");
  return 0;
}
