#include <bits/stdc++.h>
using namespace std;
const int sz = 1e6 + 6;
int z[sz], n;
void z_fun(string s) {
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    int j = 0;
    if (i <= r) {
      j = min(r - i + 1, z[i - l]);
      z[i] = j;
    }
    for (; j < n && i + j < n; j++) {
      if (s[j] != s[i + j]) break;
      ++z[i];
    }
    if (z[i] + i - 1 >= r) {
      l = i;
      r = z[i] + i - 1;
    }
  }
  return;
}
int main() {
  string s;
  cin >> s;
  n = (int)s.size();
  z_fun(s);
  vector<int> ps, m;
  for (int i = 0; i < n; i++) {
    if (i + z[i] == n) {
      ps.push_back(z[i]);
      if (i != 0 && z[i] != 1) m.push_back(z[i] - 1);
    } else if (z[i] != 0)
      m.push_back(z[i]);
  }
  int maxi = -1;
  sort(m.begin(), m.end());
  for (int i = 0; i < ps.size(); i++) {
    int index = lower_bound(m.begin(), m.end(), ps[i]) - m.begin();
    if (index != (int)m.size()) maxi = max(maxi, ps[i]);
  }
  if (maxi != -1)
    for (int i = 0; i < maxi; i++) cout << s[i];
  else
    cout << "Just a legend";
  return cout << endl, 0;
}
