#include <bits/stdc++.h>
using namespace std;
vector<int> fail(const string &s) {
  int n = s.length();
  vector<int> v(n + 1, 0);
  int tmp = 0;
  for (int i = 1; i < n; i++) {
    while (tmp && s[tmp] != s[i]) tmp = v[tmp];
    if (s[tmp] == s[i]) tmp++;
    v[i + 1] = tmp;
  }
  return v;
}
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> v = fail(s);
  if (v[n] == 0)
    cout << "Just a legend";
  else {
    int f = 0;
    for (int i = 1; i < n; i++) {
      if (v[i] == v[n]) {
        f = v[i];
        break;
      }
    }
    if (f) {
      for (int i = 0; i < f; i++) cout << s[i];
    } else if (v[v[n]] == 0)
      cout << "Just a legend";
    else
      for (int i = 0; i < v[v[n]]; i++) cout << s[i];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  solve();
}
