#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, k;
  while (cin >> n >> m) {
    long long temp1 = 0, temp2, i = 1;
    while (1) {
      if (temp1 + i > m) break;
      temp1 += i;
      if (i == n)
        i = 1;
      else
        i++;
    }
    cout << m - temp1 << endl;
  }
}
