#include <iostream>
bool has_unique_digits(int number)
{
bool hash_table[10] = { false };
while (number != 0)
{
if (!hash_table[number % 10])
{
hash_table[number % 10] = true;
number /= 10;
}
else
{
return false;
}
}
return true;
}
int main()
{
int number;
std::cin >> number;
for (int i = 1000; i < 10000; i++)
{
if (i % number == 0 && has_unique_digits(i))
{
std::cout << i << std::endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKYm9vbCBoYXNfdW5pcXVlX2RpZ2l0cyhpbnQgbnVtYmVyKQp7CiAgICBib29sIGhhc2hfdGFibGVbMTBdID0geyBmYWxzZSB9OwoKICAgIHdoaWxlIChudW1iZXIgIT0gMCkKICAgIHsKICAgICAgICBpZiAoIWhhc2hfdGFibGVbbnVtYmVyICUgMTBdKQogICAgICAgIHsKICAgICAgICAgICAgaGFzaF90YWJsZVtudW1iZXIgJSAxMF0gPSB0cnVlOwogICAgICAgICAgICBudW1iZXIgLz0gMTA7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIHRydWU7Cn0KCmludCBtYWluKCkKewogICAgaW50IG51bWJlcjsKICAgIHN0ZDo6Y2luID4+IG51bWJlcjsKCiAgICBmb3IgKGludCBpID0gMTAwMDsgaSA8IDEwMDAwOyBpKyspCiAgICB7CiAgICAgICAgaWYgKGkgJSBudW1iZXIgPT0gMCAmJiBoYXNfdW5pcXVlX2RpZ2l0cyhpKSkKICAgICAgICB7CiAgICAgICAgICAgIHN0ZDo6Y291dCA8PCBpIDw8IHN0ZDo6ZW5kbDsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=