#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int mp[305], temp[305];
vector<int> ans, lit;
struct node {
  int left, right;
};
node coo[305];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, cnt, ta, ti, maxn, i, j, k;
  while (cin >> n >> m) {
    maxn = -INF;
    ans.clear();
    lit.clear();
    memset(mp, 0, sizeof(mp));
    memset(temp, 0, sizeof(temp));
    cnt = 1;
    for (i = 1; i <= n; i++) cin >> mp[i];
    for (i = 1; i <= m; i++) cin >> coo[i].left >> coo[i].right;
    for (i = 1; i <= n; i++) {
      ta = -INF, ti = INF;
      lit.clear();
      memcpy(temp, mp, sizeof(mp));
      for (j = 1; j <= m; j++) {
        if (i <= coo[j].right && i >= coo[j].left) continue;
        for (k = coo[j].left; k <= coo[j].right; k++) temp[k]--;
        lit.push_back(j);
      }
      for (j = 1; j <= n; j++) {
        ta = max(ta, temp[j]);
        ti = min(ti, temp[j]);
      }
      if (maxn < ta - ti) {
        maxn = ta - ti;
        ans.swap(lit);
      }
    }
    cout << maxn << endl;
    cout << ans.size() << endl;
    if (ans.size()) {
      cout << ans[0];
      for (i = 1; i < ans.size(); i++) {
        cout << " " << ans[i];
      }
    }
    cout << endl;
  }
  return 0;
}
