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