#include <bits/stdc++.h>
using namespace std;
long long int mult(long long int a, long long int b) {
  return ((a * b) % 1000000007);
}
long long int pow_m(long long int a, long long int p) {
  if (p == 0) {
    return 1;
  } else if (p == 1) {
    return a;
  }
  long long int temp = pow_m(a, p / 2);
  if (p % 2 == 0) {
    return mult(temp, temp);
  } else {
    return mult(mult(temp, temp), a);
  }
}
long long int inv(long long int a) {
  if (a == 0) {
    return 0;
  }
  return pow_m(a, 1000000007 - 2);
}
long long int nChooseK(long long int n, long long int k) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  for (int i = 0; i < k; ++i) {
    answer = mult(answer, n - i);
  }
  for (int i = 2; i <= k; ++i) {
    answer = mult(answer, inv(i));
  }
  return answer;
}
long long int nChooseK(long long int n, long long int k,
                       vector<long long int>& pre_mult,
                       vector<long long int>& pre_div) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  answer = mult(answer, pre_mult[n]);
  answer = mult(answer, pre_div[n - k]);
  answer = mult(answer, pre_div[k]);
  return answer;
}
vector<long long int> coordinate_compression(vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  vector<long long int> answer = input;
  long long int index = 0;
  while (index < b.size()) {
    answer[index] = mp[answer[index]];
  }
  return answer;
}
map<long long int, long long int> get_coordinate_compression_map(
    vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  return mp;
}
int64_t my_pow(int64_t base, int64_t height) {
  if (height == 0) {
    return 1;
  }
  if (height % 2 == 0) {
    int64_t temp = my_pow(base, height / 2);
    return (temp * temp) % 1000000007;
  } else {
    int64_t temp = my_pow(base, height / 2);
    return ((temp * temp) % 1000000007) * base % 1000000007;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> dp(s.size(), 0);
  int n = s.size();
  int i = 1;
  int length = 0;
  while (i < n) {
    if (s[i] == s[length]) {
      dp[i] = length + 1;
      i++;
      length++;
    } else {
      if (length == 0) {
        dp[i] = 0;
        i++;
      } else {
        length = dp[length - 1];
      }
    }
  }
  if (dp[n - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  string temp = s.substr(0, dp[n - 1]);
  if (temp.size() + 2 <= s.size()) {
    int64_t temp_hash = 0;
    for (int j = 0; j < temp.size(); ++j) {
      temp_hash = (temp_hash * 26 + (temp[j] - 'a')) % 1000000007;
    }
    int64_t current_hash = 0;
    for (int i = 1; i < temp.size() + 1; ++i) {
      current_hash = (current_hash * 26 + (s[i] - 'a')) % 1000000007;
    }
    if (current_hash == temp_hash) {
      cout << temp << "\n";
      return 0;
    }
    for (int i = temp.size() + 1; i < n - 1; ++i) {
      current_hash = (current_hash + 1000000007 -
                      ((s[i - temp.size()] - 'a') *
                       my_pow(26, temp.size() - 1) % 1000000007)) %
                     1000000007;
      current_hash = (current_hash * 26 + (s[i] - 'a')) % 1000000007;
      if (current_hash == temp_hash &&
          s.substr(i - temp.size() + 1, temp.size()) == temp) {
        cout << temp << "\n";
        return 0;
      }
    }
  }
  if (dp[dp[n - 1] - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  } else {
    cout << s.substr(0, dp[dp[n - 1] - 1]) << "\n";
  }
  return 0;
}
