#include <bits/stdc++.h>
using namespace std;
int n, m, u, v;
int a[200010];
int upd[200010];
vector<pair<int, int>> rng;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    upd[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    rng.push_back(make_pair(u - 1, v - 1));
  }
  int maxx = 0;
  vector<int> vec, sol;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) upd[k] = 0;
    for (int j = 0; j < m; j++) {
      if (rng[j].first > i || rng[j].second < i) {
        vec.push_back(j);
        upd[rng[j].first]--;
        upd[rng[j].second + 1]++;
      }
    }
    int sum = 0;
    int minn = 1000000000;
    for (int k = 0; k < n; k++) {
      sum += upd[k];
      if (k != i) minn = min(minn, a[k] + sum);
    }
    if (a[i] - minn > maxx) {
      maxx = a[i] - minn;
      sol.clear();
      for (int k = 0; k < vec.size(); k++) sol.push_back(vec[k]);
    }
    vec.clear();
  }
  cout << maxx << endl;
  cout << sol.size() << endl;
  for (int i = 0; i < sol.size(); i++) cout << sol[i] + 1 << " ";
  cout << endl;
  return 0;
}
