#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 350;
vector<pair<long long, long long> > adj[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(9);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n + 10);
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<pair<long long, long long> > inter(m + 10);
  for (long long i = 1; i <= m; ++i) {
    long long l, r;
    cin >> l >> r;
    inter[i] = {l, r};
  }
  long long mx = -1e9;
  vector<long long> ans;
  for (long long i = 1; i <= n; ++i) {
    vector<long long> b = a;
    vector<long long> curvec;
    for (long long j = 1; j <= m; ++j) {
      pair<long long, long long> gap = inter[j];
      if (i >= gap.first && i <= gap.second) {
        curvec.push_back(j);
        for (long long j = gap.first; j <= gap.second; ++j) {
          --b[j];
        }
      }
    }
    long long curmx = *max_element(b.begin() + 1, b.begin() + n + 1);
    long long curmn = *min_element(b.begin() + 1, b.begin() + n + 1);
    long long diff = curmx - curmn;
    if (diff > mx) {
      mx = diff;
      ans = curvec;
    }
  }
  cout << mx << '\n';
  cout << ans.size() << '\n';
  for (auto &x : ans) cout << x << " ";
  cout << '\n';
  return 0;
}
