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