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