#include <bits/stdc++.h>
int main() {
  int n, m, i, c = 0, d = 0;
  scanf("%d%d", &n, &m);
  while (1) {
    for (i = 1; i <= n; i++) {
      m -= i;
      if (m < 0) {
        m = m + i;
        c = c + m;
        d = 1;
        break;
      } else if (m == 0) {
        d = 1;
        break;
      }
    }
    if (d == 1) break;
  }
  printf("%d", c);
}
