#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001000;
int main() {
  int z[MAXN];
  memset(z, 0, sizeof(z));
  string s;
  cin >> s;
  int n = s.size();
  int toCheck = 0;
  int last = 0;
  for (int i = 1; i < n; i++) {
    int j = last + z[last] - i;
    if (j < 0)
      j = 0;
    else
      j = min(z[i - last], j);
    while (s[i + j] == s[j] && i + j < n) j++;
    z[i] = j;
    if (i + z[i] > last + z[last]) last = i;
  }
  for (int i = 1; i < n; i++) {
    int j = z[i];
    if (i + z[i] == n) j--;
    toCheck = max(j, toCheck);
  }
  int ans = -1;
  for (int i = n - toCheck; i < n; i++) {
    if (i + z[i] == n) {
      ans = z[i];
      break;
    }
  }
  if (ans == -1)
    cout << "Just a legend";
  else {
    for (int i = 1; i < n; i++)
      if (z[i] >= ans) {
        for (int j = 0; j < ans; j++) cout << s[i + j];
        break;
      }
  }
  return 0;
}
