#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct p {
  ll l, r;
};
bool check(p p1, ll a) { return a >= p1.l && a <= p1.r; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m, i, e, j, foo, ans = 0, ans1, ans2, best = 0;
  cin >> n >> m;
  vector<ll> a(n);
  for (i = 0; i < n; i++) cin >> a[i];
  vector<p> b(m);
  for (i = 0; i < m; i++) {
    cin >> b[i].l >> b[i].r;
    b[i].l--;
    b[i].r--;
  }
  for (i = 0; i < n; i++) {
    for (e = 0; e < n; e++) {
      if (i == e) continue;
      foo = 0;
      for (j = 0; j < m; j++) {
        if (check(b[j], i) && !check(b[j], e)) {
          foo++;
        }
      }
      if (ans < a[e] - a[i] + foo) {
        ans = a[e] - a[i] + foo;
        ans1 = i;
        ans2 = e;
        best = foo;
      }
    }
  }
  cout << ans << endl;
  cout << best << endl;
  for (i = 0; i < m; i++) {
    if (check(b[i], ans1) && !check(b[i], ans2)) {
      cout << i + 1 << " ";
    }
  }
  return 0;
}
