#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, i, j, x, y, z, m, n;
  cin >> n >> m;
  c = 1;
  while (1) {
    if (m - c < 0) break;
    m = m - c;
    c = c + 1;
    if (c > n) c = 1;
  }
  cout << m << endl;
  return 0;
}
