#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
const long long mod = 1e9 + 7;
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int arr[M][2], nums[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &nums[i]);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &arr[i][0], &arr[i][1]);
    arr[i][0]--;
    arr[i][1]--;
  }
  int a = 0, b = 0;
  int res, ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      res = 0;
      for (int k = 0; k < M; k++) {
        if (arr[k][0] <= i && arr[k][1] >= i &&
            !(arr[k][0] <= j && arr[k][1] >= j)) {
          res++;
        }
      }
      if (res + nums[j] - nums[i] > ans) {
        a = i;
        b = j;
      }
      ans = max(ans, res + nums[j] - nums[i]);
    }
  }
  printf("%d\n", ans);
  vector<int> ans2;
  for (int k = 0; k < M; k++) {
    if (arr[k][0] <= a && arr[k][1] >= a &&
        !(arr[k][0] <= b && arr[k][1] >= b)) {
      ans2.push_back(k + 1);
    }
  }
  printf("%d\n", ans2.size());
  for (int i : ans2) {
    printf("%d ", i);
  }
}
