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