#include <bits/stdc++.h>
using namespace std;
int ans = -1, acnt, tp[2], n, m, a[301], l[301], r[301];
inline bool isin(int a, int t) { return a >= l[t] && a <= r[t]; }
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", &l[i], &r[i]);
  for (int i = 1, cnt; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cnt = a[i] - a[j];
      for (int k = 1; k <= m; k++)
        if (!isin(i, k) && isin(j, k)) cnt++;
      if (cnt > ans) {
        ans = cnt;
        tp[0] = i;
        tp[1] = j;
        acnt = cnt - a[i] + a[j];
      }
    }
  }
  printf("%d\n%d\n", ans, acnt);
  for (int k = 1; k <= m; k++)
    if (!isin(tp[0], k) && isin(tp[1], k)) printf("%d ", k);
}
