#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
char s[1000006];
int p[1000006], n;
bool mark[1000006];
int main() {
  cin >> s;
  p[0] = 0;
  n = 1;
  for (int i = 1; s[i]; i++, n++) {
    int j = p[i - 1];
    while (j && s[j] != s[i]) j = p[j - 1];
    if (s[j] == s[i]) j++;
    p[i] = j;
    if (i) mark[p[i - 1]] = 1;
  }
  for (int i = p[n - 1]; i; i = p[i - 1])
    if (mark[i]) {
      s[i] = '\0';
      printf("%s\n", s);
      return 0;
    }
  puts("Just a legend");
  return 0;
}
