#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], i = 0;
  memset(a, 0, sizeof(a));
  while (m > 0) {
    if (m >= i + 1)
      a[i] += i + 1;
    else {
      cout << m << endl;
      return 0;
    }
    m -= (i + 1);
    i = (i + 1) % n;
  }
  cout << m << endl;
  return 0;
}
