#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int p[N], d[N], ans;
string s;
void prefix(string s) {
  int j = 0;
  for (int i = 1; i < (int)s.size(); i++) {
    while (j > 0 && s[i] != s[j]) j = p[j - 1];
    j += (s[i] == s[j]);
    p[i] = j;
  }
}
int main() {
  cin >> s;
  if (s.size() < 3) {
    cout << "Just a legend";
    return 0;
  }
  prefix(s);
  if (p[s.size() - 1] == 0) {
    cout << "Just a legend";
    return 0;
  }
  for (int i = 0; i < s.size(); i++) d[p[i]]++;
  if (d[p[s.size() - 1]] >= 2) ans = p[s.size() - 1];
  if (ans == 0) {
    int pos = s.size() - 1;
    while (pos - 1 > 0 && p[pos - 1] > 0) pos--;
    string t = s.substr(pos, s.size() - pos);
    for (int i = 0; i <= s.size(); i++) d[i] = 0;
    prefix(t);
    for (int i = 0; i < t.size(); i++) d[p[i]]++;
    if (d[p[t.size() - 1]] >= 1) ans = p[t.size() - 1];
    if (ans != 0) {
      string t1 = s.substr(0, ans);
      string t2 = s.substr(s.size() - ans, ans);
      if (t1 == t2)
        cout << t1;
      else
        cout << "Just a legend";
    } else
      cout << "Just a legend";
  } else
    for (int i = 0; i < ans; i++) cout << s[i];
  return 0;
}
