#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
bool smax(T &x, L y) {
  return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
bool smin(T &x, L y) {
  return y < x ? (x = y, true) : false;
}
void calc();
const int MAXN = 1e6 + 15;
string s;
bool can;
int f[MAXN];
vector<int> vec;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cerr << "HELLO WORLD :|\n";
  cin >> s;
  calc();
  int v = f[s.size()];
  while (true) {
    if (v <= 0) return cout << "Just a legend\n", false;
    for (int j = 1; j < (int)s.size(); j++) {
      if (f[j] == v) return cout << s.substr(0, v) << '\n', false;
    }
    v = f[v];
  }
}
void calc() {
  memset(f, false, sizeof f);
  int len = 0;
  string t = s;
  f[0] = -1;
  for (int i = 1; i <= (int)t.size(); i++) {
    len = f[i - 1];
    while (~len) {
      if (t[len] == t[i - 1]) break;
      len = f[len];
    }
    f[i] = len + 1;
  }
}
