#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int Next[1000005];
bool vis[1000005];
int len;
void getnext() {
  Next[0] = -1;
  int j = -1, i = 0;
  while (i < len) {
    if (j == -1 || s[i] == s[j]) {
      i++;
      j++;
      Next[i] = j;
    } else {
      j = Next[j];
    }
  }
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  getnext();
  for (int i = 1; i < len; i++) vis[Next[i]] = 1;
  int i = Next[len];
  while (i) {
    if (vis[i]) {
      for (int j = 0; j < i; j++) cout << s[j];
      cout << endl;
      break;
    } else
      i = Next[i];
  }
  if (i == 0) cout << "Just a legend" << endl;
  return 0;
}
