#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, sum = 0, rem, x;
  cin >> n >> m;
  i = 0;
  while (x = (i % n) + 1) {
    m -= x;
    if (m < 0) {
      m += x;
      cout << m << "\n";
      return 0;
    }
    i++;
  }
  return 0;
}
