#include <bits/stdc++.h>
using namespace std;
struct player {
  int initial_section;
  int final_section;
  int time;
  int profit;
};
int main() {
  int number_of_section;
  int number_of_player;
  int profit = 0;
  cin >> number_of_section;
  cin >> number_of_player;
  player database[100];
  for (int i = 0; i < number_of_player; i++) {
    cin >> database[i].initial_section;
    cin >> database[i].final_section;
    cin >> database[i].time;
    cin >> database[i].profit;
  }
  for (int i = 1; i < number_of_player; i++) {
    int j;
    player temp = database[i];
    for (j = i - 1; j >= 0 && temp.time < database[j].time; j--)
      database[j + 1] = database[j];
    database[j + 1] = temp;
  }
  for (int i = 1; i <= number_of_section; i++) {
    for (int j = 0; j < number_of_player; j++) {
      if (i >= database[j].initial_section && i <= database[j].final_section) {
        profit += database[j].profit;
        break;
      }
    }
  }
  cout << profit;
  return 0;
}
