#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int n, m;
int ans;
int main() {
scanf("%d %d", &n, &m);
ans = m;
while (true) {
for (int i = 1;i <= n;++i) {
if (ans >= i) {
ans -= i;
}
else {
goto x;
}
}
}
x: printf("%d\n", ans);
return 0;
}