#include <bits/stdc++.h>
using namespace std;
long long p = 1000000007;
long long Pow(long long, long long, long long);
long long Pow(long long a, long long b, long long p) {
  if (b == 0) return 1;
  return !(b % 2) ? (Pow(a, b / 2, p) % p) * (Pow(a, b / 2, p) % p) % p
                  : (a % p) * (Pow(a, b - 1, p)) % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i;
  long long n, m, h = 0, ans = 0, min1, max1;
  cin >> n >> m;
  vector<long long> a(n + 1), l(m + 1), r(m + 1), x(n + 1), d[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    x[i] = a[i];
  }
  for (i = 1; i <= m; i++) cin >> l[i] >> r[i];
  for (i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (i < l[j] || i > r[j]) {
        for (long long k = l[j]; k <= r[j]; k++) x[k]--;
        d[i].push_back(j);
      }
    }
    sort(x.begin() + 1, x.end());
    max1 = x[n];
    min1 = x[1];
    if (max1 - min1 > ans) {
      ans = max1 - min1;
      h = i;
    }
    for (long long k = 1; k <= n; k++) x[k] = a[k];
  }
  cout << ans << "\n" << d[h].size() << "\n";
  for (i = 0; i < d[h].size(); i++) cout << d[h][i] << " ";
  cout << "\n";
}
