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