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