#include <bits/stdc++.h>
using namespace std;
int z[1000005], pre[1000005];
void zalgo(string str, int n) {
  int l = 0, r = 0;
  z[0] = n;
  for (int i = 1; i < n; i++) {
    if (i > r) {
      int j = 0, k = i;
      while (k < n && str[k] == str[j]) {
        k++;
        j++;
      }
      k--;
      z[i] = j;
      if (k > r) {
        r = k;
        l = i;
      }
    } else {
      int k = i;
      int k1 = k - l;
      int b = r - k + 1;
      if (z[k1] < b)
        z[k] = z[k1];
      else if (z[k1] > b)
        z[k] = b;
      else {
        k = r + 1;
        while (k < n && str[k] == str[b]) {
          k++;
          b++;
        }
        k--;
        if (k > r) {
          r = k;
          l = i;
        }
        z[i] = b + r - k;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string str;
  cin >> str;
  int final = 0;
  int n = str.length();
  zalgo(str, n);
  pre[1] = z[1];
  for (int i = 2; i < n; i++) {
    pre[i] = max(pre[i - 1], z[i]);
  }
  for (int i = 1; i < n; i++) {
    if (pre[i - 1] >= z[i] && (z[i] == n - i)) {
      final = max(final, z[i]);
    }
  }
  if (final == 0)
    cout << "Just a legend\n";
  else
    cout << str.substr(0, final) << "\n";
}
