#include <bits/stdc++.h>
using namespace std;
const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},
                       {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
const long long int LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const int SIZE = 16;
const double PI = acos(-1);
int N, M;
int main() {
  scanf("%d %d", &N, &M);
  int indx = 1;
  while (true) {
    if (indx > N) indx = 1;
    if (M - indx < 0) break;
    M -= indx;
    indx++;
  }
  printf("%d\n", M);
  return 0;
}
