#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 * 1000 * 1000 + 10;
string s;
int nxt[maxn], mx, cur, x;
bool mark[maxn];
int main() {
  cin >> s;
  if (s.length() < 3) {
    cout << "Just a legend";
    return 0;
  }
  for (int i = 2; i <= s.length(); i++) {
    while (cur && s[i - 1] != s[cur]) cur = nxt[cur];
    if (s[i - 1] == s[cur]) cur++;
    nxt[i] = cur;
    if (i == s.length()) {
      x = nxt[i];
      while (!mark[x]) x = nxt[x];
      if (x == 0) {
        cout << "Just a legend";
        return 0;
      }
      cout << s.substr(0, x);
      return 0;
    } else {
      x = nxt[i];
      while (!mark[x]) {
        mark[x] = 1;
        x = nxt[x];
      }
    }
  }
  return 0;
}
