#include <bits/stdc++.h>
using namespace std;
long long n, m, c, d, e, i, j, k, l, ab[1000001], ac[1000001];
int main() {
  cin >> n >> m;
  i = 1;
  j = 1;
  while (m >= 0) {
    m = m - i;
    ab[j] = m;
    j++;
    i++;
    if (i > n) i = 1;
  }
  cout << ab[j - 2];
}
