#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e6 + 5;
int f[N], ans = -1, m;
string s;
int getNextL(int len, char c) {
  while (len && s[len] != c) len = f[len - 1];
  if (c == s[len]) len++;
  return len;
}
void computeF() {
  f[0] = 0;
  for (int i = 1; i < s.size(); i++) {
    f[i] = getNextL(f[i - 1], s[i]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  computeF();
  ans = f[s.size() - 1];
  m = *max_element(f, f + s.size() - 1);
  while (ans > m) ans = f[ans - 1];
  if (ans)
    cout << s.substr(0, ans);
  else
    cout << "Just a legend";
  return 0;
}
