#include <bits/stdc++.h>
using namespace std;
map<int, int> mapp;
string s;
int Z[1000001];
void Zval() {
  int left = 0, right = 0;
  for (int k = 1; k < s.size(); k++) {
    if (k > right) {
      left = right = k;
      while (right < s.size() && s[right] == s[right - left]) right++;
      Z[k] = right - left;
      right--;
    } else {
      int k1 = k - left;
      if (Z[k1] < right - k + 1)
        Z[k] = Z[k1];
      else {
        left = k;
        while (right < s.size() && s[right] == s[right - left]) right++;
        Z[k] = right - left;
        right--;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  int n, m;
  int i, j;
  cin >> s;
  n = s.size();
  Zval();
  int maxz = -1, ans = -1;
  for (i = 0; i < n; i++) {
    if (Z[i] == n - i && maxz >= n - i) {
      ans = i;
      break;
    }
    maxz = max(maxz, Z[i]);
  }
  if (ans == -1)
    cout << "Just a legend";
  else
    cout << s.substr(ans, n);
  return 0;
}
