#include <bits/stdc++.h>
using namespace std;
string s;
int kmp[1000007];
vector<int> vec;
set<int> q;
int main() {
  cin >> s;
  int t = 0, pos = -1, x;
  x = s.length();
  kmp[0] = 0;
  for (int i = 1; i < x; i++) {
    while (t > 0 && s[i] != s[t]) {
      t = kmp[t - 1];
    }
    if (s[i] == s[t]) t++;
    kmp[i] = t;
  }
  if (!kmp[x - 1]) {
    cout << "Just a legend";
    return 0;
  }
  while (t > 0) {
    vec.push_back(t);
    t = kmp[t - 1];
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < x - 1; i++) q.insert(kmp[i]);
  for (set<int>::reverse_iterator k = q.rbegin(); k != q.rend(); k++) {
    if (binary_search(vec.begin(), vec.end(), *k)) {
      pos = *k;
      break;
    }
  }
  if (pos == -1) {
    cout << "Just a legend";
    return 0;
  }
  for (int i = 0; i < pos; i++) cout << s[i];
}
