#include <bits/stdc++.h>
const int INF = (int)1e9 + 5;
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<int, int> > segment(m);
  for (int i = 0; i < m; i++) {
    cin >> segment[i].first >> segment[i].second;
    segment[i].first--, segment[i].second--;
  }
  vector<int> res;
  int ans = -INF;
  for (int i = 0; i < n; i++) {
    vector<int> t;
    vector<int> cnt(n + 1);
    int mx = a[i];
    for (int j = 0; j < m; j++) {
      int l = segment[j].first;
      int r = segment[j].second;
      if (l <= i && r >= i) {
        continue;
      }
      cnt[l] += -1;
      cnt[r + 1] += 1;
      t.push_back(j + 1);
    }
    int mn = INF;
    for (int j = 1; j <= n; j++) {
      cnt[j] += cnt[j - 1];
      mn = min(mn, a[j - 1] + cnt[j - 1]);
    }
    if (mx - mn > ans) {
      ans = mx - mn;
      res = t;
    }
  }
  cout << ans << '\n' << res.size() << '\n';
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << " ";
  }
  cout << '\n';
  return 0;
}
