#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N], b[N], n, m, mx, mn, d = -1e9;
pair<int, int> p[N];
vector<int> sol, v;
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &a[i]);
  };
  for (long long i = 1; i <= m; i++) {
    scanf("%d", &p[i].first);
    scanf("%d", &p[i].second);
  }
  for (int i = 1; i <= n; i++) {
    v.clear();
    for (long long j = 1; j <= n; j++) {
      b[j] = a[j];
    }
    for (long long q = 1; q <= m; q++) {
      if (i >= p[q].first && i <= p[q].second) {
        continue;
      }
      v.push_back(q);
      for (long long j = p[q].first; j <= p[q].second; j++) {
        b[j]--;
      }
    }
    mx = *max_element(b + 1, b + 1 + n);
    mn = *min_element(b + 1, b + 1 + n);
    if (a[i] == mx) {
      if (d < abs(mx - mn)) {
        d = abs(mx - mn);
        sol = v;
      }
    }
  }
  printf("%d\n", d);
  printf("%d\n", (int)sol.size());
  for (auto x : sol) printf("%d ", x);
  return 0;
}
