#include <bits/stdc++.h>
using namespace std;
int a[100][100] = {0};
int main() {
  int n, m, i = 1;
  int s = 0;
  cin >> n >> m;
  while (m) {
    m = m - i;
    if (m < 0) {
      m = m + i;
      break;
    }
    if (i == n)
      i = 1;
    else
      i++;
  }
  cout << m;
  return 0;
}
