#include <bits/stdc++.h>
using namespace std;
const int INF = 2000001;
struct Node {
  int l;
  int r;
} node[310];
int main() {
  int n, m, number[310];
  map<int, vector<int> > stl;
  cin >> n >> m;
  for (int a = 1; a <= n; a++) cin >> number[a];
  for (int a = 1; a <= m; a++) cin >> node[a].l >> node[a].r;
  int Maxx = 0, index = -1;
  int vis[310];
  for (int a = 1; a <= n; a++) {
    memset(vis, 0, sizeof(vis));
    for (int b = 1; b <= m; b++) {
      if (node[b].l <= a && a <= node[b].r) continue;
      stl[a].push_back(b);
      for (int c = node[b].l; c <= node[b].r; c++) vis[c]--;
    }
    int minn = INF, maxx = -INF;
    for (int d = 1; d <= n; d++) {
      if (number[d] + vis[d] < minn) minn = number[d] + vis[d];
      if (number[d] + vis[d] > maxx) maxx = number[d] + vis[d];
    }
    if (maxx - minn > Maxx) {
      Maxx = maxx - minn;
      index = a;
    }
  }
  cout << Maxx << endl;
  cout << stl[index].size() << endl;
  for (int a = 0; a < stl[index].size(); a++) cout << stl[index][a] << " ";
  return 0;
}
