#include <bits/stdc++.h>
using namespace std;
const int N = 1000023;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a);
    b /= 2;
    a = (a * a);
  }
  return ans;
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.first > b.first)
    return 1;
  else if (a.first == b.first)
    return (a.second < b.second);
  else
    return 0;
}
long long int hash1[N];
long long int p_pow[N];
string str;
long long int n;
void cal_pow() {
  long long int p = 31;
  for (long long int i = 0; i < N; i++) {
    if (i != 0)
      p_pow[i] = (p_pow[i - 1] * p) % 1000000007;
    else
      p_pow[i] = 1;
  }
}
void calc() {
  hash1[0] = str[0] - 'a' + 1;
  for (long long int i = 1; i <= str.size() - 1; i++) {
    hash1[i] = (hash1[i - 1] + (p_pow[i] * (str[i] - 'a' + 1)) % 1000000007) %
               1000000007;
  }
}
long long int check(long long int val, long long int len) {
  for (long long int i = 1; i < n - len; i++) {
    long long int temp =
        (p_pow[n - 1 - i] * (hash1[i + len - 1] - hash1[i - 1] + 1000000007) %
         1000000007) %
        1000000007;
    if (temp == val) return 1;
  }
  return 0;
}
void solve() {
  cin >> str;
  cal_pow();
  calc();
  vector<pair<long long int, long long int>> v;
  n = str.size();
  for (long long int i = 0; i < n - 1; i++) {
    long long int f = (p_pow[n - 1] * hash1[i]) % 1000000007;
    long long int s =
        (p_pow[i] * (hash1[n - 1] - hash1[n - i - 2] + 1000000007) %
         1000000007) %
        1000000007;
    if (f == s) v.push_back({i + 1, f});
  }
  if (!v.size()) {
    cout << "Just a legend" << endl;
    return;
  }
  sort((v).begin(), (v).end());
  v.push_back({n + 3, 1});
  long long int l = 0, r = v.size() - 1;
  if (!check(v[0].second, v[0].first)) {
    cout << "Just a legend" << endl;
    return;
  }
  while ((l + 1) < r) {
    long long int mid = (l + r) / 2;
    if (check(v[mid].second, v[mid].first))
      l = mid;
    else
      r = mid;
  }
  long long int idx = 0, len = v[l].first;
  while (len--) {
    cout << str[idx];
    idx++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int Test;
  Test = 1;
  long long int t = 0;
  while (t++ < Test) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
