#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int l[N], r[N];
vector<int> e;
int main() {
  int n, m;
  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]);
  }
  int ans = 0, t1, t2;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int Max = a[i];
      int Min = a[j];
      for (int k = 1; k <= m; k++) {
        if (l[k] <= i && i <= r[k]) continue;
        if (l[k] <= j && j <= r[k]) {
          Min--;
        }
      }
      int tmp = Max - Min;
      if (tmp > ans) {
        t1 = i;
        t2 = j;
        ans = tmp;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (l[i] <= t1 && t1 <= r[i]) continue;
    if (l[i] <= t2 && t2 <= r[i]) {
      e.push_back(i);
    }
  }
  printf("%d\n", ans);
  printf("%d\n", e.size());
  for (auto it : e) {
    printf("%d ", it);
  }
}
