#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int z = n * (n + 1) / 2;
  m = m % z;
  for (int i = 1; i <= n; i++) {
    if (m < i) {
      cout << m << endl;
      return;
    }
    m -= i;
  }
}
int main() { solve(); }
