#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int start = 1;
  while (1) {
    if (m >= start)
      m -= start;
    else
      break;
    start++;
    if (start == (n + 1)) start = 1;
    if (m == 0) break;
  }
  cout << m;
  return 0;
}
