#include <bits/stdc++.h>
using namespace std;
string s;
int z[(1000000 + 5)];
void input() { getline(cin, s); }
int M[(1000000 + 5)];
void solve() {
  z[0] = s.size();
  int l = 0, r = 0;
  for (int i = 1; i <= s.size() - 1; ++i) {
    if (i > r) {
      l = r = i;
      while (s[r] == s[r - l] && r < s.size()) ++r;
      r--;
      z[i] = r - l + 1;
    } else if (z[i - l] < r - i + 1) {
      z[i] = z[i - l];
    } else {
      l = i;
      while (s[r] == s[r - l] && r < s.size()) ++r;
      r--;
      z[i] = r - l + 1;
    }
  }
  M[1] = z[1];
  for (int i = 2; i <= s.size() - 1; ++i) M[i] = max(z[i], M[i - 1]);
  int res = -1;
  for (int i = s.size() - 1; i >= 1; i--)
    if (z[i] == s.size() - 1 - i + 1) {
      if (M[i - 1] >= z[i]) res = i;
    }
  if (res != -1) {
    for (int i = res; i <= s.size() - 1; ++i) cout << s[i];
  } else
    cout << "Just a legend";
}
int main() {
  iostream::sync_with_stdio(0);
  input();
  solve();
}
