#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 1010;
queue<int> q;
int n,k;
int main(){
cin >> n >> k;
for(int i = 1;i <= n;i++) q.push(i);
int s = 0;
while(q.size() > 1){
int flag = 1;
int t = q.front();
q.pop();
s++;
if(s % k == 0 || s % 10 == k) flag = 0;
if(flag) q.push(t);
}
cout << q.front() << endl;
return 0;
}