#include <bits/stdc++.h>
using namespace std;
const int maxn = 3020;
int arr[maxn];
int x[maxn], y[maxn];
vector<int> plan;
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
    for (int i = 1; i <= m; i++) scanf("%d %d", &x[i], &y[i]);
    int max_val = 0, best_i = -1, best_j = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == j) continue;
        int sum = 0;
        int big = arr[i];
        int small = arr[j];
        for (int k = 1; k <= m; k++) {
          if (x[k] <= j && j <= y[k]) {
            small--;
            if (x[k] <= i && i <= y[k]) big--;
          }
        }
        if (max_val < big - small)
          best_i = i, best_j = j, max_val = big - small;
      }
    }
    plan.clear();
    for (int k = 1; k <= m; k++) {
      if (x[k] <= best_j && best_j <= y[k]) {
        plan.push_back(k);
      }
    }
    printf("%d\n%d\n", max_val, plan.size());
    if (plan.size() == 0)
      printf("\n");
    else
      for (int i = 0; i < plan.size(); i++)
        printf("%d%c", plan[i], i == plan.size() - 1 ? '\n' : ' ');
  }
  return 0;
}
