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