#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[305];
vector<int> v;
int pre[305], a[305];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
  }
  int cnt;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      cnt = 0;
      int xx = a[j] - a[i];
      for (int k = 1; k <= m; k++) {
        if (i >= p[k].first && i <= p[k].second &&
            (j < p[k].first || j > p[k].second)) {
          pre[cnt++] = k;
          xx++;
        }
      }
      if (ans < xx) {
        ans = xx;
        v.clear();
        for (int i = 0; i < cnt; i++) v.push_back(pre[i]);
      }
    }
  }
  cout << ans << endl;
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  puts("");
  return 0;
}
