#include <bits/stdc++.h>
using namespace std;
vector<int> fail(string s) {
  int n = s.length();
  vector<int> res(n);
  res[0] = 0;
  for (int i = 1, k = 0; i < n; i++) {
    while (k > 0 && s[k] != s[i]) {
      k = res[k - 1];
    }
    if (s[i] == s[k]) k++;
    res[i] = k;
  }
  return res;
}
vector<int> p[1001000];
int a[1001000];
int dfs(int x) {
  int r = 1;
  for (int i = 0; i < p[x].size(); i++) r += dfs(p[x][i]);
  a[x] = r - 1;
  return r;
}
vector<int> f;
string s;
string sol(int x) {
  if (x == 0) return "Just a legend";
  if (a[x] + 1 >= 3) {
    return s.substr(0, x);
  }
  return sol(f[x - 1]);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  int n = s.length();
  f = fail(s);
  for (int i = 0; i < n; i++) p[f[i]].push_back(i + 1);
  dfs(0);
  cout << sol(n);
  return 0;
}
