#include <bits/stdc++.h>
const long long ary = 1e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
using namespace std;
string second;
long long z[ary], c[ary], mx;
void zf() {
  long long l = 1, r = 1;
  for (int i = 1; i < (long long)second.size(); i++) {
    z[i] = max(0ll, min(z[i - l], r - i + 1));
    c[z[i]]++;
    while (i + z[i] < (long long)second.size() &&
           second[z[i]] == second[i + z[i]]) {
      z[i]++;
      c[z[i]]++;
    }
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> second;
  zf();
  for (int i = 0; i < (long long)second.size(); i++) {
    if (i + z[i] == (long long)second.size()) {
      if (c[z[i]] > 1) {
        for (int j = i; j < i + z[i]; j++) {
          cout << second[j];
        }
        return 0;
      }
    }
  }
  cout << "Just a legend";
}
