#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

struct doublepair{
  int a, b;
};

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ull n;
  cin >> n;
  std::vector<ull> three;
  std::vector<ull> five;
  for (ull i=3;i < n;i *=3) {
    three.push_back(i);
  }
  for (ull i=5;i < n;i *=5) {
    five.push_back(i);
  }

  bool is_find {false};
  doublepair ans;
  for (int i = 0;i < three.size();++i) {
    for (int j = 0;j < five.size();++j) {
      if (three[i] + five[j] > n) {
        break;
      } else if (three[i] + five[j] == n) {
        ans.a = i+1;
        ans.b = j+1;
        is_find = true;
        break;
      }
    }
    if (is_find == true) break;
  }
  if (is_find) cout << ans.a << ' ' << ans.b << '\n';
  else cout << -1 << '\n';
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define Swap(a, b) do { typeof(a) T = (a); a = b; b = T; } while(0)

static inline int
input() {
    int x = 0, f = 0, c = getchar();
    while(c < '0' || c > '9') { f ^= (c == '-'), c = getchar(); }
    while(c > 47 && c < 58) { x = x * 10 + c - '0', c = getchar(); }
    return f ? -x : x;
}

static inline void
Asc64(long long *a, const int sz) {
    int shift = 0, elem[256];
    long long x = 0, *aux = (long long*)malloc(sizeof(long long)*sz);

    if(aux == nullptr) { exit(EXIT_FAILURE); }

    while(shift < 64) {
        int bucket[256] = {0};
        for(int i = 0; i < sz; ++i) {
            x = (a[i] >> shift) & 255;
            ++bucket[x];
            aux[i] = a[i];
        }

        elem[0] = 0;

        for(int i = 0; i < 255; ++i) {
            elem[i + 1] = elem[i] + bucket[i];
        }

        for(int i = 0; i < sz; ++i) {
            x = (aux[i] >> shift) & 255; a[elem[x]] = aux[i];
            ++elem[x];
        }

        shift += 8;
    }

    free(aux);
}

int main() {
    int n = input();
    int len = 0, sizeS = 0, sizeT = 0;
    long long S[n], T[n];
    char temp[11];

    for(int i = 0; i < n; ++i) {
        if(!scanf("%s", temp)) {
            exit(EXIT_FAILURE);
        }

        len = (int)strlen(temp);
        S[i] = T[i] = 0;

        if(temp[0] == '!') {
            --len;
            for(int j = 0; j < len; ++j) {
                T[sizeT] = T[sizeT] * 27 + (temp[j + 1] - 'a' + 1);
            }
            ++sizeT;
        }
        else {
            for(int j = 0; j < len; ++j) {
                S[sizeS] = S[sizeS] * 27 + (temp[j] - 'a' + 1);
            }
            ++sizeS;
        }
    }

    Asc64(S, sizeS);
    Asc64(T, sizeT);

    int idxS = 0, idxT = 0;
    long long check = 0;
    while(idxS < sizeS && idxT < sizeT) {
        check = S[idxS] - T[idxT];
        if(!check) {
        memset(temp, '\n', 11);
            len = 0;
            while(S[idxS]) {
                temp[len++] = 'a' + S[idxS] % 27 - 1;
                S[idxS] /= 27;
            }
            for(int i = 0; i < len/2; ++i) {
                Swap(temp[i], temp[len - 1 - i]);
            }
            return !puts(temp);
        }
        else if(check < 0) {
            ++idxS;
        }
        else {
            ++idxT;
        }
    }

    return !puts("satisfiable");
}