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