#include <bits/stdc++.h>
using namespace std;
int ans;
string s;
void Z_value(string& s, vector<int>& z) {
  z.resize(s.size());
  int i, j, left, right, len = s.size();
  left = right = 0;
  z[0] = len;
  for (i = 1; i < (int)s.size(); ++i) {
    j = max(min(z[i - left], right - i), 0);
    for (; i + j < len && s[i + j] == s[j]; ++j)
      ;
    z[i] = j;
    if (i + z[i] > right) {
      left = i;
      right = i + z[i];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  vector<int> z;
  Z_value(s, z);
  int maxz = 0;
  for (int i = 1; i < (int)s.size(); ++i) {
    if (z[i] == (int)s.size() - i and maxz >= (int)s.size() - i) {
      ans = s.size() - i;
      break;
    }
    maxz = max(maxz, z[i]);
  }
  if (ans == 0)
    cout << "Just a legend" << '\n';
  else
    cout << s.substr(0, ans) << '\n';
}
