#include <bits/stdc++.h>
using namespace std;
pair<int, int> b[200005];
int n, m, a[200005];
int solve(int x, int y) {
  int mn = 0, mx = 0;
  mn = a[x];
  mx = a[y];
  for (int i = 1; i <= m; i++) {
    if (x >= b[i].first && x <= b[i].second &&
        !(y >= b[i].first && y <= b[i].second)) {
      mn--;
    }
  }
  return mx - mn;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i].first >> b[i].second;
  }
  int imax = -1e9 + 7;
  int mnn, mxx;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int q = solve(i, j);
      if (imax < q) {
        mnn = i, mxx = j;
        imax = q;
      }
    }
  }
  if (imax == -1e9 + 7) {
    cout << 0 << endl << 0;
    return 0;
  }
  cout << imax << endl;
  int mn = a[mnn];
  int mx = a[mxx];
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    if (mnn >= b[i].first && mnn <= b[i].second &&
        !(mxx >= b[i].first && mxx <= b[i].second)) {
      mn--;
      ans++;
    }
  }
  cout << ans << endl;
  mn = a[mnn];
  mx = a[mxx];
  for (int i = 1; i <= m; i++) {
    if (mnn >= b[i].first && mnn <= b[i].second &&
        !(mxx >= b[i].first && mxx <= b[i].second)) {
      cout << i << ' ';
    }
  }
}
