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