#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const long long mod = (int)1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[i] = make_pair(x - 1, y - 1);
  }
  int x = 0;
  int y = 0;
  int anv = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int nanv = 0;
      for (int k = 0; k < m; k++) {
        if (v[k].first <= j && j <= v[k].second &&
            (i < v[k].first || v[k].second < i))
          nanv++;
      }
      if (chmax(anv, a[i] - a[j] + nanv)) {
        x = i;
        y = j;
      }
    }
  }
  int cnt = 0;
  vector<int> mv;
  for (int i = 0; i < m; i++) {
    if (v[i].first <= y && y <= v[i].second &&
        (x < v[i].first || v[i].second < x)) {
      cnt++;
      mv.push_back(i);
    }
  }
  cout << anv << endl;
  cout << cnt << endl;
  for (auto p : mv) cout << p + 1 << ' ';
}
