#include <bits/stdc++.h>
using namespace std;
const int INF = 80000000;
const int MOD = 998244353;
const int N = 1000001;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
vector<int> z(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
  };
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a = z(s);
  int maxi = 0;
  int res = 0;
  for (int i = 0; i < int(n); i++) {
    if (a[i] + i == n && maxi >= a[i]) {
      res = a[i];
      break;
    }
    maxi = max(maxi, a[i]);
  }
  if (res == 0) {
    cout << "Just a legend"
         << "\n";
  } else
    cout << s.substr(0, res) << "\n";
}
