#include <bits/stdc++.h>
using namespace std;
const int MX = 1000001;
const int MI = 100001;
const int MT = 10001;
char a[MX];
int z[MX], x[MX], y[MX];
vector<int> z_function(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_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a;
  cin >> a;
  vector<int> z = z_function(a);
  int w = z.size(), max1 = INT_MIN, max2 = INT_MIN;
  for (int i = w - 1; i > -1; --i) {
    if (z[i] == w - i) {
      if (z[i] > max1)
        max2 = max1, max1 = z[i];
      else if (z[i] > max2)
        max2 = z[i];
    }
    x[i] = max1;
    y[i] = max2;
  }
  w = w - 1;
  int ans = 0;
  for (int i = 1; i < w; ++i) {
    if (z[i] == w - i + 1) {
      if (y[i] > ans) ans = y[i];
    } else {
      int s = min(x[i], min(z[i], x[w - z[i] + 1]));
      if (s > ans) ans = s;
    }
  }
  if (ans == 0) {
    cout << "Just a legend" << endl;
    return 0;
  }
  for (int i = 0; i < ans; ++i) cout << a[i];
  cout << endl;
  return 0;
}
