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