#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int N = 400;
int n, m, a[N], b[N], l[N], r[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int ans = *max_element(a + 1, a + 1 + n) - *min_element(a + 1, a + 1 + n);
  for (int i = 0; i < (int)(m); ++i) cin >> l[i] >> r[i];
  vector<int> fin;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) b[j] = a[j];
    vector<int> res;
    for (int j = 0; j < (int)(m); ++j) {
      if (l[j] <= i && i <= r[j]) {
        res.emplace_back(j + 1);
        for (int k = l[j]; k <= r[j]; ++k) {
          --b[k];
        }
      }
    }
    int maxx = INT_MIN;
    for (int j = 1; j <= n; ++j) uax(maxx, b[j]);
    if (maxx - b[i] > ans) {
      ans = maxx - b[i];
      fin.clear();
      for (int x : res) fin.emplace_back(x);
    }
  }
  cout << ans << '\n';
  cout << int(fin.size()) << '\n';
  for (int x : fin) cout << x << ' ';
  cout << '\n';
  return 0;
}
