#include <bits/stdc++.h>
using namespace std;
string s;
int z[1111111];
void pre() {
  int l = 0, r = 0;
  for (int i = 1; i < s.size(); i++) {
    if (i >= r) {
      while (i + z[i] < s.size()) {
        if (s[z[i]] == s[z[i] + i])
          z[i]++;
        else
          break;
      }
      if (l + z[i] - 1 > r) {
        l = i, r = i + z[i] - 1;
      }
    } else {
      int can = z[i - l];
      if (i + can - 1 <= r) {
        z[i] = can;
      } else {
        int cur;
        for (cur = r; cur <= i + can && cur < s.size(); cur++) {
          if (s[cur - l] != s[cur]) {
            break;
          }
        }
        z[i] = cur - i;
        if (l + z[i] - 1 > r) {
          l = i, r = i + z[i] - 1;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s;
  pre();
  int mx = 0;
  for (int i = 0; i < s.size(); i++) {
    if (z[i] > z[mx]) mx = i;
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i == mx) continue;
    if (z[i] == 0) continue;
    if (z[s.size() - z[i]] == z[i]) {
      ans = max(ans, z[i]);
    }
  }
  if (ans)
    cout << s.substr(0, ans) << endl;
  else
    cout << "Just a legend" << endl;
  ;
  return 0;
}
