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