#include <bits/stdc++.h>
using namespace std;
const vector<pair<long long int, long long int> > dir4 = {
    {-1, 0}, {1, 0}, {0, 1}, {0, -1}};
const vector<pair<long long int, long long int> > dir8 = {
    {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  ;
  vector<int> L(M), R(M);
  for (int i = 0; i < (int)(M); i++) cin >> L[i] >> R[i], L[i]--;
  int mx = INT_MIN;
  vector<int> res;
  for (int i = 0; i < (int)(N); i++) {
    vector<int> C(N + 1);
    for (int j = 0; j < (int)(M); j++)
      if (((L[j]) <= (i) && (i) < (R[j]))) C[L[j]]++, C[R[j]]--;
    for (int j = 0; j < (int)(N); j++) C[j + 1] += C[j];
    vector<int> B(N);
    for (int j = 0; j < (int)(N); j++) B[j] = A[j] - C[j];
    if (chmax(mx, *max_element((B).begin(), (B).end()) -
                      *min_element((B).begin(), (B).end()))) {
      res.clear();
      for (int j = 0; j < (int)(M); j++)
        if (((L[j]) <= (i) && (i) < (R[j]))) res.push_back(j + 1);
    }
  }
  cout << (mx) << endl;
  ;
  cout << (res.size()) << endl;
  ;
  for (int i = 0; i < (int)(res.size()); i++) {
    if (i) cout << " ";
    cout << res[i];
  }
  cout << endl;
  return 0;
}
