#include <bits/stdc++.h>
using namespace std;
template <int N, class Ty = unsigned long long>
class SegTree {
  Ty eachData[N * 2];
  inline void setEachSubL(int begin, int middle, int range, int pos,
                          const Ty& v) {
    while (true) {
      pos += pos;
      range >>= 1;
      if (begin <= middle - range) {
        eachData[pos + 1] = min(v, eachData[pos + 1]);
        if (begin == middle - range) {
          break;
        }
        middle -= range;
      } else {
        ++pos;
      }
    }
  }
  inline void setEachSubR(int middle, int end, int range, int pos,
                          const Ty& v) {
    while (true) {
      pos += pos;
      range >>= 1;
      if (middle + range <= end) {
        eachData[pos] = min(v, eachData[pos]);
        if (end == middle + range) {
          break;
        }
        middle += range;
        ++pos;
      }
    }
  }

 public:
  inline SegTree() {
    assert((N & (N - 1)) == 0);
    clear();
  }
  inline void clear() { memset(eachData, -1, sizeof(eachData)); }
  inline void setEach(int begin, int end, const Ty& v) {
    if (begin == end) {
      return;
    }
    assert(begin < end);
    assert(0 <= begin && begin <= N);
    assert(0 <= end && end <= N);
    if (begin == 0) {
      if (end == N) {
        eachData[1] = min(eachData[1], v);
        return;
      }
      setEachSubR(0, end, N, 1, v);
      return;
    } else if (end == N) {
      setEachSubL(begin, N, N, 1, v);
      return;
    }
    int offset = 0;
    int pos = 2;
    int range = N >> 1;
    while (true) {
      int middle = offset + range;
      if (end <= middle) {
        if (end == middle) {
          if (begin == offset) {
            eachData[pos] = min(eachData[pos], v);
            return;
          }
          setEachSubL(begin, middle, range, pos, v);
          return;
        }
      } else if (middle <= begin) {
        ++pos;
        if (middle == begin) {
          if (end == middle + range) {
            eachData[pos] = min(v, eachData[pos]);
            return;
          }
          setEachSubR(middle, end, range, pos, v);
          return;
        }
        offset = middle;
      } else {
        setEachSubL(begin, middle, range, pos, v);
        setEachSubR(middle, end, range, pos + 1, v);
        return;
      }
      pos += pos;
      range >>= 1;
    }
  }
  inline Ty get(int idx) const {
    int pos = N + idx;
    Ty ret = eachData[pos];
    pos >>= 1;
    while (pos) {
      ret = min(ret, eachData[pos]);
      pos >>= 1;
    }
    return ret;
  }
};
SegTree<131072> Tree;
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<tuple<int, int, int> > LRC;
  for (int n = 0; n < N; ++n) {
    int l, r, c;
    scanf("%d%d%d", &l, &r, &c);
    LRC.emplace_back(l - 1, r - 1, c);
  }
  sort(LRC.begin(), LRC.end());
  Tree.setEach(0, 1, 0);
  for (auto& lrc : LRC) {
    unsigned long long c = Tree.get(get<0>(lrc));
    if (c != (unsigned long long)-1) {
      Tree.setEach(get<0>(lrc) + 1, get<1>(lrc) + 1, c + get<2>(lrc));
    }
  }
  unsigned long long c = Tree.get(N - 1);
  printf("%lld\n", c);
  return 0;
}
