#include <bits/stdc++.h>
using namespace std;
int a[400];
int l[400], r[400];
int n, m;
bool check(int i, int p) {
  if (l[p] <= i && i <= r[p])
    return true;
  else
    return false;
}
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i];
  }
  int tmp;
  int maxpos, minpos, anst;
  int ans = -0x3f3f3f3f;
  int used = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      used = 0;
      tmp = a[i] - a[j];
      for (int k = 1; k <= m; k++) {
        if (!check(i, k) && check(j, k)) tmp++, used++;
      }
      if (tmp > ans) {
        ans = tmp;
        maxpos = i, minpos = j;
        anst = used;
      }
    }
  }
  cout << ans << endl << anst << endl;
  for (int i = 1; i <= m; i++) {
    if (!check(maxpos, i) && check(minpos, i)) cout << i << " ";
  }
  cout << endl;
  return 0;
}
