import sequtils,strutils # let results = (proc():seq[int]= # # (2017 + (2017 * 2017)^2017) mod M # proc impl(m:int): int = # let x = (2017 * 2017) mod m # var ans = 1 # for _ in 0..<2017 : ans = (ans * x) mod m # ans = (ans + 2017) mod m # return ans # return 0 & toSeq(1..2017).map(impl) # )() const results = [0, 0, 0, 2, 2, 1, 2, 2, 2, 2, 6, 7, 2, 6, 2, 11, 2, 13, 2, 12, 6, 2, 18, 5, 2, 21, 6, 2, 2, 11, 26, 18, 2, 29, 30, 16, 2, 10, 12, 32, 26, 12, 2, 12, 18, 11, 28, 21, 2, 23, 46, 47, 6, 28, 2, 51, 2, 50, 40, 37, 26, 19, 18, 2, 34, 6, 62, 61, 30, 5, 16, 38, 2, 45, 10, 71, 50, 51, 32, 13, 66, 56, 12, 17, 2, 81, 12, 11, 18, 79, 56, 58, 74, 80, 68, 31, 2, 89, 72, 29, 46, 79, 98, 15, 58, 86, 28, 28, 2,28, 106, 47, 2, 46, 50, 51, 98, 110, 96, 30, 26, 84, 80, 53, 18, 96, 2, 83, 34, 98, 6, 34, 62, 107,128, 56, 98, 84, 74, 54, 86, 68, 38, 84, 2, 11, 118, 23, 10, 11, 146, 134, 50, 47, 128, 111, 110, 27, 92, 134, 66, 51, 56, 83, 94, 161, 100, 137, 2, 84, 166, 164, 98, 108, 98, 121, 18, 155, 168, 87, 146, 159, 58, 80, 74, 121, 80, 183, 162, 2, 126, 113, 98, 129, 186, 71, 170, 107, 128, 10, 146, 128,180, 156, 98, 176, 118, 74, 162, 183, 86, 164, 134, 38, 28, 141, 2, 142, 28, 191, 106, 149, 158, 187, 2, 146, 46, 146, 50, 201, 166, 128, 98, 203, 110, 21, 214, 92, 30, 40, 146, 57, 84, 218, 202, 121, 176, 240, 18, 17, 96, 115, 2, 51, 210, 251, 162, 40, 98, 121, 6, 11, 34, 203, 194, 81, 240, 257, 262, 177, 56, 198, 98, 149, 84, 271, 74, 85, 54, 173, 226, 250, 68, 165, 38, 221, 84, 135, 2, 285, 156, 89, 118, 274, 170, 96, 10, 29, 160, 97, 146, 184, 134, 281, 50, 141, 200, 287, 282, 221, 266, 114, 266, 69, 184, 191, 250, 250, 134, 40, 226, 242, 212, 183, 218, 71, 246, 137, 258, 303, 326, 330, 266, 47, 304, 61, 2, 20, 84, 272, 166, 18, 164, 23, 98, 281, 108, 54, 98, 115, 296, 110, 194, 216, 332, 251, 346, 149, 266, 68, 146, 335, 340, 326, 58, 191, 80, 232, 258, 299, 306, 240, 266, 263, 370, 221, 162, 214, 2, 72, 126, 83, 304, 156, 290, 51, 322, 227, 186, 342, 266, 166, 170, 296, 304, 171, 326, 156, 10, 107, 146, 3, 128, 266, 382, 56, 156, 84, 98, 103, 176, 221, 118, 37, 74, 266, 162, 332, 392, 416, 86, 186, 164, 209, 346, 421, 38, 324, 242, 227, 356, 415, 2, 106, 142, 11, 246, 373, 410, 187, 106, 317, 370, 385, 158, 346, 410, 11, 226, 121, 146, 381, 46, 134, 146, 331, 50, 18, 430, 353, 166, 398, 128, 182, 98, 266, 436, 433, 110, 128, 256, 341, 450, 227, 92, 221, 30, 452, 40, 377, 386, 84, 298, 212, 326, 186, 218, 124, 202, 83, 366, 205, 422, 98, 240, 326, 18, 464, 266, 220, 346, 137, 366, 78, 2, 281, 304, 422, 210, 87, 506, 191, 418, 164, 40, 221, 98, 491, 380, 281, 266, 51, 272, 127, 34, 296, 466, 421, 194, 488, 346, 155, 506, 422, 524, 456, 530, 266, 446, 513, 326, 182, 198, 521, 98, 246, 422, 429, 358, 263, 546, 69, 74, 408, 362, 491, 54, 517, 452, 227, 226, 557, 250, 217, 350, 46, 448, 380, 322, 245, 506, 164, 370, 113, 422, 396, 290, 148, 574, 515, 446, 100, 380, 293, 410, 461, 274, 528, 170, 297, 96, 107, 306, 185, 326, 506, 458, 209, 396, 542, 146, 334, 184, 128,134, 326, 584, 283, 354, 359, 446, 162, 506, 360, 594, 176, 282, 574, 530, 21, 266, 488, 114, 79, 578, 346, 382, 392, 498, 47, 506, 109, 250, 164, 250, 591, 134, 513, 40, 38, 546, 3, 242, 126, 534, 356, 506, 403, 218, 568, 396, 359, 246, 209, 464, 296, 258, 191, 632, 79, 326, 470, 330, 149, 266, 506, 380, 649, 638, 410, 396, 568, 2, 2, 20, 596, 422, 513, 272, 380, 506, 146, 18, 523, 506, 221, 366, 659, 98, 240, 626, 297, 454, 128, 54, 471, 98, 217, 464, 203, 646, 429, 110, 639, 546, 491, 216, 79, 686, 165, 606, 92, 346, 235, 506, 656, 266, 518, 68, 605, 146, 324, 696, 539, 702, 446, 326, 387,58, 461, 556, 98, 446, 284, 232, 611, 258, 128, 668, 712, 306, 734, 240, 202, 266, 11, 636, 515, 370, 135, 596, 232, 162, 617, 214, 436, 2, 578, 72, 557, 506, 114, 464, 464, 686, 506, 156, 214, 674, 90, 436, 554, 322, 116, 614, 421, 186, 380, 342, 12, 266, 535, 166, 272, 562, 341, 296, 111, 698, 203, 566, 611, 722, 19, 156, 611, 10, 625, 506, 115, 546, 524, 404, 337, 530, 51, 266, 446, 786, 404, 56, 209, 562, 740, 84, 246, 98, 12, 512, 695, 586, 129, 632, 431, 530, 821, 450, 765, 74, 216, 266, 362, 162, 268, 332, 471, 810, 731, 416, 70, 506, 504, 186, 812, 586, 591, 632, 205, 770, 731, 846, 787, 38, 299, 324, 506, 242, 642, 656, 205, 786, 422, 846, 589, 2, 281, 106, 863, 142, 645, 446, 396,682, 380, 810, 471, 410, 473, 626, 860, 546, 344, 758, 44, 370, 686, 828, 666, 602, 464, 346, 623, 410, 867, 458, 266, 674, 695, 570, 359, 146, 81, 832, 485, 498, 521, 134, 335, 146, 281, 786, 500, 50, 183, 18, 446, 430, 296, 812, 584, 626, 287, 398, 890, 590, 121, 182, 839, 98, 566, 266, 905, 902,425, 900, 931, 578, 685, 128, 695, 726, 64, 812, 258, 450, 191, 700, 914, 566, 45, 696, 884, 506, 812, 452, 686, 518, 359, 856, 632, 866, 204, 84, 884, 298, 901, 212, 732, 810, 506, 186, 49, 218, 471, 124, 71, 690, 837, 572, 524, 366, 137, 696, 65, 914, 501, 98, 632, 734, 442, 326, 883, 514, 992, 464, 806, 266, 172, 220, 380, 346, 513, 638, 863, 366, 731, 78, 240, 2, 0, 786, 20, 810, 823, 422, 156, 210, 272, 596, 53, 506, 464, 702, 359, 930, 996, 164, 487, 554, 23, 736, 530, 98, 250, 1008, 281,898, 812, 800, 380, 786, 401, 572, 905, 794, 601, 650, 464, 34, 503, 296, 51, 466, 461, 948, 586, 194, 436, 488, 569, 346, 495, 686, 584, 506, 251, 422, 865, 1058, 147, 456, 506, 530, 417, 266, 571, 446, 68, 1052, 266, 866, 350, 182, 335, 198, 576, 1064, 61, 98, 326, 246, 772, 422, 75, 976, 191, 906, 843, 812, 184, 546, 599, 620, 396, 626, 591, 408, 299, 362, 16, 1046, 887, 610, 611, 1074, 856, 1010, 941, 786, 263, 226, 981, 1118, 506, 250, 596, 780, 856, 914, 1035, 46, 968, 1014, 942, 380, 146, 322, 830, 814, 999, 506, 898, 164, 83, 370, 201, 686, 824, 422, 539, 396, 1065, 290, 216, 148, 821, 574, 435, 1094, 202, 1026, 1001, 100, 815, 962, 436, 876, 731, 994, 471, 1046, 504, 274, 557, 528,21, 170, 777, 886, 1082, 686, 715, 698, 422, 898, 566, 778, 625, 326, 504, 506, 950, 458, 973, 806,996, 994, 506, 542, 1118, 146, 500, 334, 404, 786, 1021, 128, 251, 738, 266, 326, 800, 1190, 707, 890, 461, 354, 230, 968, 28, 446, 491, 162, 775, 506, 121, 360, 512, 594, 1110, 176, 209, 898, 632, 574, 981, 530, 620, 640, 863, 266, 1067, 488, 1063, 114, 266, 702, 98, 578, 295, 346, 749, 382, 982, 392, 366, 498, 416, 676, 76, 506, 1059, 740, 1028, 882, 51, 164, 702, 250, 1055, 1226, 545, 770, 1133, 1150, 1271, 678, 624, 38, 864, 1186, 1178, 644, 63, 242, 811, 126, 227, 1178, 229, 356, 821, 506,1277, 1050, 121, 866, 1112, 568, 539, 1046, 125, 1010, 749, 898, 11, 862, 649, 1118, 744, 296, 1247, 258, 786, 848, 466, 1290, 626, 738, 260, 986, 729, 470, 758, 330, 346, 812, 162, 930, 1271, 506, 568, 1046, 700, 1316, 791, 1306, 877, 410, 942, 1066, 11, 568, 13, 674, 446, 2, 1019, 694, 677, 596, 1094, 1098, 1283, 1190, 1011, 950, 1040, 380, 587, 1186, 519, 146, 1055, 18, 1241, 1206, 1348, 506, 1305, 906, 932, 366, 275, 1346, 1096, 98, 1271, 240, 107, 626, 623, 988, 398, 1146, 916, 128, 848, 54, 182, 1166, 1098, 98, 408, 914, 731, 1162, 337, 902, 364, 1346, 1367, 1130, 1178, 110, 531, 1342, 128, 546, 752, 1196, 183, 922, 812, 786, 731, 1394, 682, 874, 227, 606, 562, 92, 50, 1058, 221, 948,582, 506, 710, 656, 1406, 266, 1316, 518, 996, 786, 377, 1324, 824, 866, 689, 324, 1046, 1418, 1441, 1262, 256, 1426, 695, 446, 507, 326, 57, 1114, 671, 786, 1196, 1190, 440, 1286, 611, 98, 1437, 1178, 1446, 284, 83, 966, 1176, 1346, 392, 994, 1187, 128, 96, 1406, 1430, 712, 98, 306, 619, 734, 1285, 982, 326, 202, 562, 1010, 799, 756, 464, 1382, 499, 1262, 396, 370, 719, 884, 213, 1346, 487, 232,137, 162, 786, 1370, 84, 214, 581, 436, 424, 2, 880, 578, 281, 830, 750, 1316, 1444, 1266, 929, 114, 54, 1226, 446, 464, 596, 1450, 1305, 506, 1261, 922, 191, 214, 901, 1442, 823, 90, 1190, 1206, 396, 554, 732, 322, 221, 116, 149, 614, 781, 1196, 491, 962, 1389, 380, 736, 342, 281, 12, 1397, 266, 856, 1316, 572, 166, 1321, 272, 144, 1346, 650, 1126, 1386, 1082, 84, 898, 821, 698, 183, 992, 1349, 566, 1475, 1402, 1464, 722, 1201, 812, 488, 950, 373, 1406, 528, 10, 1217, 1422, 1316, 506, 543, 914, 422, 546, 191, 524, 1346, 1206, 1526, 1140, 895, 530, 891, 856, 803, 266, 536, 446, 506, 786, 1052, 404, 388, 866, 854, 1020, 182, 562, 721, 740, 1587, 898, 1064, 246, 436, 98, 1316, 12, 791, 1330, 595, 1514, 458, 586, 1523, 950, 452, 1454, 961, 1254, 812, 530, 574, 1646, 591, 450, 620, 1592, 661,74, 1053, 216, 1514, 266, 436, 362, 392, 162, 1046, 268, 962, 1166, 1073, 1306, 1631, 810, 996, 1568, 396, 1254, 227, 70, 994, 1346, 914, 504, 1118, 186, 1031, 812, 1262, 586, 1343, 1436, 791, 1478, 1022, 1052, 611, 770, 423, 1580, 997, 846, 947, 1638, 1475, 890, 1041, 1152, 245, 1178, 505, 506, 214, 242, 164, 642, 366, 1514, 1594, 1064, 686, 786, 858, 422, 1567, 846, 971, 1452, 1283, 866, 240, 1146, 725, 106, 10, 1730, 401, 1010, 515, 1514, 491, 446, 1470, 396, 1262, 1554, 1511, 380, 1169, 810, 293, 1346, 1560, 410, 992, 1350, 461, 626, 366, 860, 54, 546, 1115, 344, 12, 758, 216, 44, 1475, 370, 446, 686, 51, 1714, 1289, 666, 1671, 1490, 660, 464, 185, 346, 84, 1514, 1348, 410, 506, 1760, 341, 458, 1761, 266, 209, 674, 898, 1592, 786, 570, 542, 1258, 1325, 146, 1098, 982, 935, 1734, 696, 1388, 1722, 498, 731, 1426, 1497, 134, 121, 1242, 326, 146, 1040, 1190, 1526, 786, 890, 500, 544, 962, 921, 1096, 1577, 18, 1630, 446, 1780, 1346, 773, 296, 966, 1730, 304, 584, 1586, 626, 1255, 1208,962, 398, 1406, 890, 421, 1514, 227, 1046, 1808, 182, 1118, 1766, 611, 98, 1259, 566, 84, 266, 1312, 1836, 1109, 1834, 636, 1358, 1503, 1834, 1325, 1866, 453, 578, 819, 1622, 971, 1066, 101, 1634, 5,1666, 1019, 64, 177, 1754, 591, 258, 47, 450, 1255, 1136, 80, 1646, 740, 914, 451, 1514, 198, 994, 164, 1646, 1724, 884, 1492, 1458, 1226, 812, 165, 1406, 764, 686, 1787, 1474, 1662, 1316, 156, 1814,677, 632, 1190, 1826, 1628, 204, 644, 1046, 821, 884, 914, 298, 1412, 1866, 1098, 1178, 746, 732, 1001, 1778, 1501, 506, 639, 186, 1697, 1020, 1200, 218, 731, 1444, 1217, 1098, 1607, 1046, 1510, 1666, 1010, 1814, 166, 1550, 221, 524, 209, 1346, 1194, 1118, 1644, 1678, 296, 1048, 1374, 914, 1877, 1486, 191, 98, 1877, 632, 171, 1722, 1397, 442, 1204, 326, 1297, 1874, 470, 1506, 156, 992, 286, 1458,812, 806, 1426, 266, 1545, 172, 506, 1218, 1984, 380, 994, 1346, 1316, 1514, 1854, 638, 1206, 1866,1748, 1370, 709, 1736, 753, 78, 1910, 240, 266, 2, 0] echo results[stdin.readLine().parseInt()]