#include <bits/stdc++.h>
using namespace std;
vector<int> prefix_function(string s) {
  int n = (int)s.length();
  vector<int> pi(n);
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  return pi;
}
vector<int> z_function(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
string inp;
int main() {
  cin >> inp;
  int len = inp.length();
  vector<int> p = prefix_function(inp);
  vector<int> z = z_function(inp);
  set<int> Map1;
  set<int> Map2;
  for (int i = 0; i < len; i++) {
    if (z[i] > 0 && z[i] + i == len) {
      Map2.insert(z[i]);
    }
    if (z[i] - 1 > 0 && z[i] + i == len) {
      Map1.insert(z[i] - 1);
    }
    if (z[i] > 0 && z[i] + i < len) {
      Map1.insert(z[i]);
    }
  }
  int mx = 0;
  for (set<int>::iterator it = Map2.begin(); it != Map2.end(); it++) {
    int k = *it;
    set<int>::iterator it1 = Map1.upper_bound(k);
    set<int>::iterator it2 = Map1.find(k);
    if (it1 != Map1.end()) {
      mx = max(mx, *it);
    }
    if (it2 != Map1.end()) {
      mx = max(mx, *it);
    }
  }
  if (mx == 0) {
    cout << "Just a legend" << endl;
  } else {
    cout << inp.substr(0, mx) << endl;
  }
  return 0;
}
