#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

#define all(x)  x.begin(),x.end()
#define v(x) vector<x>
#define nl '\n'
#define fxd(x) fixed << setprecision(x)
template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;


ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extGCD(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll modInverse(ll A, ll M) {
    ll x, y;
    ll g = extGCD(A, M, x, y);
    
    if (g != 1) {
        return -1;
    } 
    else {
        return (x % M + M) % M;
    }
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    ll n , m; cin >> n >> m;
    ll minv = modInverse(n,m);
    if(minv == -1)
    {
        cout << "No such integer exists.";
    }
    else
    {
        cout << minv;
    }
}