#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, d = 0;
  vector<int> res, help;
  cin >> n >> m;
  vector<int> mas(n);
  vector<pair<int, int>> ot(m);
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ot[i].first >> ot[i].second;
  }
  for (int imax = 0; imax < n; imax++) {
    for (int imin = 0; imin < n; imin++) {
      if (imin != imax) {
        for (int i = 0; i < m; i++) {
          if (imin >= ot[i].first - 1 && imin <= ot[i].second - 1 &&
              (imax < ot[i].first - 1 || imax > ot[i].second - 1)) {
            help.push_back(i);
          }
        }
        if (mas[imax] - mas[imin] + (int)help.size() > d) {
          d = mas[imax] - mas[imin] + (int)help.size();
          res.clear();
          for (int i = 0; i < help.size(); i++) {
            res.push_back(help[i]);
          }
        }
        help.clear();
      }
    }
  }
  cout << d << endl;
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] + 1 << " ";
  }
  return 0;
}
