#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, a[300], l[300], r[300], b[300];
  vi bsolv;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  int sol = -1e9;
  for (int i = 0; i < n; ++i) {
    memcpy(b, a, sizeof a);
    vi solv;
    for (int j = 0; j < m; ++j) {
      if (i >= l[j] && i <= r[j]) {
        solv.push_back(j);
        for (int k = l[j]; k <= r[j]; ++k) b[k]--;
      }
    }
    auto [mi, ma] = minmax_element(b, b + n);
    if (*ma - *mi > sol) {
      sol = *ma - *mi;
      bsolv = solv;
    }
  }
  cout << sol << '\n' << bsolv.size() << '\n';
  for (int x : bsolv) cout << x + 1 << ' ';
}
