#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> temp;
  vector<pair<int, int>> q(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> q[i].first >> q[i].second;
  vector<int> used;
  vector<int> temp2;
  int diff = INT_MIN, mx;
  for (int i = 0; i < n; i++) {
    temp = a;
    mx = INT_MIN;
    temp2.clear();
    for (int j = 0; j < m; j++) {
      if (q[j].first <= i + 1 && i + 1 <= q[j].second) {
        for (int k = q[j].first - 1; k < q[j].second; k++) temp[k]--;
        temp2.push_back(j + 1);
      }
    }
    for (int j = 0; j < n; j++) mx = max(mx, temp[j]);
    if (mx - temp[i] > diff) {
      diff = mx - temp[i];
      used = temp2;
    }
  }
  cout << diff << endl << used.size() << endl;
  for (int i : used) cout << i << " ";
  return 0;
}
