#include <bits/stdc++.h>
long long int mod = 1000000007;
using namespace std;
int n, m;
vector<int> a(301);
int l[301], r[301];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i];
  }
  int an = 0;
  vector<int> in;
  for (int i = 1; i <= n; i++) {
    vector<int> b(301);
    vector<int> ans;
    for (int j = 1; j <= n; j++) {
      b[j] = a[j];
    }
    for (int j = 1; j <= m; j++) {
      if (i >= l[j] && i <= r[j]) {
        continue;
      }
      ans.push_back(j);
      for (int k = l[j]; k <= r[j]; k++) {
        b[k]--;
      }
    }
    int mx = -1000000000, mn = 1000000000;
    for (int j = 1; j <= n; j++) {
      mx = max(mx, b[j]);
      mn = min(mn, b[j]);
    }
    if (mx - mn > an) {
      an = mx - mn;
      in = ans;
    }
  }
  cout << an << endl;
  cout << in.size() << endl;
  for (int i = 0; i < in.size(); i++) {
    cout << in[i] << " ";
  }
  cout << endl;
  return 0;
}
