#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[301];
int l[301], r[301];
void INPUT() {
  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];
}
void SOLVE() {
  int res = 0;
  int ans[301], tam[301];
  int sl = 0;
  int i, j, k;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i == j)
        continue;
      else {
        int dem = 0;
        for (k = 1; k <= m; k++)
          if (l[k] <= j & j <= r[k] & (l[k] > i || r[k] < i)) {
            dem++;
            tam[dem] = k;
          }
        if (res < a[i] - a[j] + dem) {
          res = a[i] - a[j] + dem;
          sl = dem;
          for (k = 1; k <= sl; k++) ans[k] = tam[k];
        }
      }
  cout << res << endl;
  cout << sl << endl;
  for (i = 1; i <= sl; i++) cout << ans[i] << " ";
}
int main() {
  INPUT();
  SOLVE();
}
