#include <bits/stdc++.h>
using namespace std;
int n, m, a = 1;
int main() {
  cin >> n >> m;
  while (true) {
    if (a % n != 0)
      a %= n;
    else if (n == 1)
      a = 1;
    if (m - a >= 0)
      m -= a;
    else
      break;
    a++;
  }
  cout << m << endl;
  return 0;
}
