#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int32_t n, m, i_thWalrus = 1;
  cin >> n >> m;
  while (m >= i_thWalrus) {
    m -= i_thWalrus;
    i_thWalrus++;
    if (i_thWalrus == n + 1) i_thWalrus = 1;
  }
  cout << m;
}
