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