#include <bits/stdc++.h>
using namespace std;
inline bool SR(int &x) { return scanf("%d", &x) == 1; }
inline bool SR(long long &x) { return scanf("%lld", &x) == 1; }
inline bool SR(double &x) { return scanf("%lf", &x) == 1; }
inline bool SR(char *s) { return scanf("%s", s) == 1; }
inline bool RI() { return true; }
template <typename I, typename... T>
inline bool RI(I &x, T &...tail) {
  return SR(x) && RI(tail...);
}
inline void SP(const int x) { printf("%d", x); }
inline void SP(const long long x) { printf("%lld", x); }
inline void SP(const double x) { printf("%.16lf", x); }
inline void SP(const char *s) { printf("%s", s); }
inline void PL() { puts(""); }
template <typename I, typename... T>
inline void PL(const I x, const T... tail) {
  SP(x);
  if (sizeof...(tail)) putchar(' ');
  PL(tail...);
}
template <typename I>
void _DOING(const char *s, I &&x) {
  cerr << s << " = " << x << endl;
}
template <typename I, typename... T>
void _DOING(const char *s, I &&x, T &&...tail) {
  int c = 0;
  while (*s != ',' || c != 0) {
    if (*s == '(' || *s == '[' || *s == '{') c++;
    if (*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << " = " << x << " , ";
  _DOING(s + 1, tail...);
}
inline int RAND() {
  static int x = 880301;
  return (x = x * 0xdefaced + 1) & 0x7fffffff;
}
const int MAX_N = 1000000 + 10;
char s[MAX_N];
int dp[MAX_N];
int cnt[MAX_N];
inline void build_kmp(int n) {
  int p = dp[0] = -1;
  for (int i = 1; i <= int(n - 1); i++) {
    while (p != -1 && s[p + 1] != s[i]) p = dp[p];
    if (s[p + 1] == s[i]) p++;
    dp[i] = p;
  }
}
int main() {
  RI(s);
  int n = strlen(s);
  build_kmp(n);
  for (int i = 0; i < int(n - 1); i++)
    if (dp[i] != -1) cnt[dp[i]]++;
  int p = dp[n - 1];
  while (~p) {
    if (cnt[p]) {
      for (int i = 0; i < int(p + 1); i++) putchar(s[i]);
      PL();
      return 0;
    }
    p = dp[p];
  }
  PL("Just a legend");
  return 0;
}
